private async void _getRecurringEvents() { RecurringEventRepository recurringEventRepository = new RecurringEventRepository(); List <RecurringEvent> listOfRecurringEvent = await Task.Run(() => recurringEventRepository.GetEvents(UserSession.UserData.Id)); EventListView.Items.Clear(); foreach (RecurringEvent recurringEvent in listOfRecurringEvent) { ListViewItem listView = new ListViewItem(new string[] { recurringEvent.Name, recurringEvent.Type, recurringEvent.EventDate.ToString() }) { Tag = recurringEvent }; EventListView.Items.Add(listView); } }
public async void _checkRecurringEvent() { EventRepository _eventRepository = new EventRepository(); RecurringEventRepository _recurringEventRepository = new RecurringEventRepository(); List <RecurringEvent> recurringEventList = _recurringEventRepository.GetEvents(UserSession.UserData.Id); foreach (RecurringEvent recurringEvent in recurringEventList) { int noOfDays = (DateTime.Now - UserSession.UserData.LastAccessDate).Days; DateTime recurringTime = UserSession.UserData.LastAccessDate; TimeSpan timeSpan = new TimeSpan(recurringEvent.EventDate.Hour, recurringEvent.EventDate.Minute, recurringEvent.EventDate.Second); recurringTime = recurringTime.Date + timeSpan; for (int i = 0; i <= noOfDays; i++) { if (recurringEvent.Status.Equals("Weekly")) { if (recurringTime.DayOfWeek != recurringEvent.EventDate.DayOfWeek) { recurringTime = recurringTime.AddDays(1); continue; } } if (recurringEvent.Status.Equals("Monthly")) { if (recurringTime.Day != recurringEvent.EventDate.Day) { recurringTime = recurringTime.AddDays(1); continue; } } if (recurringEvent.Status.Equals("Yearly")) { string recurringTimeString = recurringTime.ToString("dd/MM"); string createdDateString = recurringEvent.EventDate.ToString("dd/MM"); if (!recurringTimeString.Equals(createdDateString)) { recurringTime = recurringTime.AddDays(1); continue; } } if (recurringTime > UserSession.UserData.LastAccessDate && recurringTime <= DateTime.Now && recurringTime > recurringEvent.EventDate) { _messageStatus = await Task.Run(() => _eventRepository.AddEvent(new Event { Name = recurringEvent.Name, Location = recurringEvent.Location, Type = recurringEvent.Type, EventDate = recurringTime, Note = recurringEvent.Note, ContactId = recurringEvent.ContactId, UserId = recurringEvent.UserId })); RecurringBackground.ReportProgress(1, "New Event has been Added"); } recurringTime = recurringTime.AddDays(1); } } }