This is the last step which i have to make alarm sound every match with current time and the current day (not date), the data of time will be taken from database which i have created before with entity framework below are models which i created , there are two table , the first is AlarmModel
public int id { get; set; }
public int dayId {get;set;}
[ForeignKey("dayId")]
public virtual Day day { get; set; }
public int sessionId { get; set; }
[ForeignKey("sessionId")]
public virtual Session session { get; set; }
public DateTime time { get; set; }
public int repeatTime { get; set; }
public String path { get; set; }
public String keterangan { get; set; }
and this is the second class DayModel
public class Day
{
public int id { get; set; }
public String nameDay { get; set; }
}
Below is the image of my alarm table enter image description here
So i just focus to the time and the day id example i set time to 08:00 and day is Sunday so 08:00 on sunday there will be sound ring that is path
I have tried this code , but I get nothing
What I have tried:
public class AlarmClock
{
public AmanContext repo { get; set; }
public AlarmClock()
{
repo = new AmanContext();
}
public DateTime GetAlarm(DateTime time)
{
DateTime alarm = DateTime.Now;
foreach (var item in repo.alarms.ToList())
{
if (time > item.time)
{
alarm = item.time;
}
}
return alarm;
}
DispatcherTimer timer = new DispatcherTimer();
public ViewAlarm()
{
this.alarmService = new AlarmService();
InitializeComponent();
timer.Interval = TimeSpan.FromSeconds(1);
timer.Tick += timer_tick;
timer.Start();
}
AlarmClock ac = new AlarmClock();
private void timer_tick(object sender, EventArgs e)
{
DateTime timeNow = DateTime.Now;
DateTime alarms = ac.GetAlarm(timeNow);
alarmlbl.Content = timeNow.ToLongTimeString();
if (timeNow > alarms)
{
}
}