Пример #1
0
 public void DoHabit(DateTime now)
 {
     if (log == null)
     {
         log = HabitLogFactory.Create(id, user_id);
     }
     log.doHabit(now, this.days_off);
 }
Пример #2
0
 public Habit(Guid id, String name, Days[] days_off, Guid user_id, DateTime created_at, HabitLog log = null)
 {
     if (isDaysDuplicateAnd7(days_off))
     {
         throw new Exception("Days Off Shouldnt be Duplicate and all weekdays");
     }
     if (name.Length < 2 || name.Length > 100)
     {
         throw new Exception("Habit name must be between 2 until 100 characters");
     }
     this.id         = id;
     this.name       = name;
     this.days_off   = days_off;
     this.user_id    = user_id;
     this.created_at = created_at;
     this.log        = log;
 }
Пример #3
0
        public static HabitLog Create(Guid id, Guid user_id, string lastState = "", IBadgeRepository badgeRepository = null)
        {
            BadgeHandler dominating   = new DominatingHandler(badgeRepository, new BadgeDominating());
            BadgeHandler Workaholic   = new WorkaholicHandler(badgeRepository, new BadgeWorkaholic());
            BadgeHandler EpicComeback = new EpicComebackHandler(badgeRepository, new BadgeEpicComeback());

            HabitLog habitlog;

            habitlog = new HabitLog(id, user_id);
            habitlog.Attach(dominating);
            habitlog.Attach(Workaholic);
            habitlog.Attach(EpicComeback);

            if (lastState == null || lastState == "")
            {
                return(habitlog);
            }

            HabitLogMemento memento = JsonSerializer.Deserialize <HabitLogMemento>(lastState);

            habitlog.LoadMemento(memento);
            return(habitlog);
        }