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 AddActivity(Activity activity, DateTime dateTime) { try { List <ActivityPropertyValue> tempList = new List <ActivityPropertyValue>(); foreach (KeyValuePair <string, string> obj in activity.PropertyValues) { ActivityProperty currentObj = activity.Properties.FirstOrDefault(data => data.Property == obj.Key); if (String.IsNullOrEmpty(obj.Value) && !currentObj.AllowNull) { throw new Exception("ERROR_FILL_ALL_FIELDS"); } tempList.Add(new ActivityPropertyValue() { ActivityPropertyId = currentObj.Id, Value = obj.Value }); } UserActivity uaObj = new UserActivity() { ActivityId = activity.Id, UserId = User.Instance.Id, DateTime = dateTime }; Conn.Insert(uaObj); foreach (ActivityPropertyValue obj in tempList) { obj.UserActivityId = uaObj.Id; } Conn.InsertRange(tempList); AchievementHandler.UpdateProgress(AchievementType.CreatedOneActivity); } catch (Exception ex) { ErrorMessage = ErrorHandler.ReturnErrorMessage(ex.Message); return(false); } return(true); }