public bool AddNotification(Notification notification, bool lastCheckIn = false) { try { if (String.IsNullOrEmpty(notification.Text) && !notification.Primary) { throw new Exception("ERROR_FILL_ALL_FIELDS"); } if (notification.Primary) { if (PrimaryNotification != null) { throw new Exception("ERROR_PRIMARY_ALREADY_EXISTS"); } } if (lastCheckIn && notification.TriggerTime > DateTime.Now) { throw new Exception("ERROR_PAST_TIME"); } if (!lastCheckIn && notification.TriggerTime < DateTime.Now) { throw new Exception("ERROR_FUTURE_TIME"); } if (!TimeCheck(notification.TriggerTime, lastCheckIn)) { throw new Exception("ERROR_TIME_INCORRECT"); } if (lastCheckIn) { notification.TriggerTime = NewTime; } Conn.Insert(notification); ToastService.SetToastForNotification(notification); if (notification.Primary) { SetPrimaryNotification(); } else { AchievementHandler.UpdateProgress(AchievementType.CreatedOneNotification); } } catch (Exception ex) { ErrorMessage = ErrorHandler.ReturnErrorMessage(ex.Message); return(false); } return(true); }
public bool UpdateNotification(Notification notification, bool lastCheckIn = false) { Notification tempNotification = Conn.GetSingleItem <Notification>("SELECT * FROM Notification WHERE Id = ?", notification.Id); try { if (tempNotification == null) { throw new Exception("ERROR_ALARM_DOESNT_EXIST"); } if (String.IsNullOrEmpty(notification.Text) && !notification.Primary) { throw new Exception("ERROR_FILL_ALL_FIELDS"); } if (lastCheckIn && notification.TriggerTime > DateTime.Now) { throw new Exception("ERROR_PAST_TIME"); } if (!lastCheckIn && notification.TriggerTime < DateTime.Now) { throw new Exception("ERROR_FUTURE_TIME"); } if (!TimeCheck(notification.TriggerTime, lastCheckIn)) { throw new Exception("ERROR_TIME_INCORRECT"); } if (lastCheckIn) { notification.TriggerTime = NewTime; } ToastService.RemoveToastFromSchedule(notification); ToastService.SetToastForNotification(notification); Conn.Update(notification); if (notification.Primary) { SetPrimaryNotification(); } } catch (Exception ex) { ErrorMessage = ErrorHandler.ReturnErrorMessage(ex.Message); return(false); } return(true); }