static string getReminderName(DateTime dateTime, ReminderType type, IRemindable dtoEntry, IHasReminder entry)
 {
     if (type == ReminderType.Birthday)
     {
         return(string.Format(LocalizedStrings.ReminderBirthday, ((CustomerDTO)dtoEntry).FullName, dateTime.Date.ToShortDateString()));
     }
     else if (type == ReminderType.ScheduleEntry)
     {
         return(string.Format(LocalizedStrings.ReminderScheduleEntry, dateTime.Date, ((ScheduleEntry)entry).Activity.Name));
     }
     else if (type == ReminderType.EntryObject)
     {
         if (entry is SuplementsEntry)
         {
             return(string.Format(LocalizedStrings.ReminderSupplements, dateTime.Date.ToShortDateString()));
         }
         if (entry is StrengthTrainingEntry)
         {
             return(string.Format(LocalizedStrings.ReminderStrengthTraining, dateTime.ToShortDateString()));
         }
         if (entry is SizeEntry)
         {
             return(string.Format(LocalizedStrings.ReminderMeasurements, dateTime.Date.ToShortDateString()));
         }
     }
     return("TODO:Name not set");
 }
        protected ReminderItem CreateReminder(string name, Profile profile, DateTime dateTime, TimeSpan?remindBefore = null, ReminderRepetitions pattern = ReminderRepetitions.Once, ReminderType type = ReminderType.Custom)
        {
            var reminder = new ReminderItem();

            reminder.Name         = name;
            reminder.Profile      = profile;
            reminder.DateTime     = dateTime;
            reminder.Repetitions  = pattern;
            reminder.Type         = type;
            reminder.RemindBefore = remindBefore;
            insertToDatabase(reminder);
            return(reminder);
        }
 public void PrepareReminder(Profile dbProfile, IRemindable dtoEntry, IHasReminder entry, IHasReminder origEntry, DateTime dateTime, ReminderType type, ReminderRepetitions repetitions)
 {
     if (dtoEntry.RemindBefore.HasValue)
     {
         if (origEntry == null || origEntry.Reminder == null)
         {
             entry.Reminder = new ReminderItem();
         }
         else
         {
             entry.Reminder = origEntry.Reminder;
         }
         //entry.Reminder.ConnectedObject = entry.ToString();
         entry.Reminder.DateTime     = dateTime;
         entry.Reminder.Profile      = dbProfile;
         entry.Reminder.Type         = type;
         entry.Reminder.RemindBefore = dtoEntry.RemindBefore != TimeSpan.Zero
                                           ? dtoEntry.RemindBefore.Value
                                           : (TimeSpan?)null;
         entry.Reminder.Repetitions = repetitions;
         entry.Reminder.Name        = getReminderName(dateTime, type, dtoEntry, entry);
         Session.SaveOrUpdate(entry.Reminder);
         dbProfile.DataInfo.ReminderHash = Guid.NewGuid();
     }
     else if (origEntry != null && origEntry.Reminder != null)
     {
         Session.Delete(origEntry.Reminder);
         entry.Reminder = null;
         dbProfile.DataInfo.ReminderHash = Guid.NewGuid();
     }
 }
        //public static ReminderItem CreateReminder<T>(ISession session,TimeSpan? remindBefore,Profile dbProfile,string name,DateTime time)
        //{
        //    ReminderItem reminder = null;
        //    if (remindBefore.HasValue)
        //    {
        //        reminder = new ReminderItem();

        //        reminder.DateTime = time;
        //        reminder.Profile = dbProfile;
        //        reminder.Type = ReminderType.EntryObject;
        //        reminder.RemindBefore = remindBefore!= TimeSpan.Zero
        //                                          ? remindBefore.Value
        //                                          : (TimeSpan?)null;
        //        reminder.Repetitions = ReminderRepetitions.Once;
        //        reminder.Name = name;
        //        reminder.ConnectedObject = typeof(T).Name+":{0}";
        //        session.Save(reminder);
        //        //dbProfile.DataInfo.LastReminderModification=...
        //    }
        //    return reminder;
        //}

        public static void CreateReminder <T>(ISession session, IHasReminder hasReminder, TimeSpan?remindBefore, Profile dbProfile, DateTime time, ReminderType type)
        {
            if (hasReminder.Reminder == null)
            {
                hasReminder.Reminder = new ReminderItem();
            }
            hasReminder.Reminder.DateTime     = time;
            hasReminder.Reminder.Profile      = dbProfile;
            hasReminder.Reminder.Type         = type;
            hasReminder.Reminder.RemindBefore = remindBefore != TimeSpan.Zero
                                              ? remindBefore.Value
                                              : (TimeSpan?)null;
            hasReminder.Reminder.Repetitions     = ReminderRepetitions.Once;
            hasReminder.Reminder.Name            = getReminderName(time, type, null, hasReminder);
            hasReminder.Reminder.ConnectedObject = typeof(T).Name + ":{0}";

            dbProfile.DataInfo.ReminderHash = Guid.NewGuid();
            //dbProfile.DataInfo.LastReminderModification=...
        }