Example #1
0
        public HabitResponse CreateHabit(HabitRequest HabitRequest, Guid UserID)
        {
            Habit         habit   = HabitFactory.Create(HabitRequest, UserID);
            List <DayOff> dayOffs = DayOffFactory.Create(HabitRequest.DaysOff, habit.ID);

            habitRepository.CreateHabit(habit);
            dayOffRepository.CreateDayOff(dayOffs);
            return(ConvertFromHabitToHabitResponse(habit));
        }
Example #2
0
        public HabitResponse UpdateHabit(Guid userId, Guid habitId, HabitRequest habitRequest)
        {
            ValidateUserID(userId, habitId);
            Habit         habit        = habitRepository.GetHabitById(habitId);
            Habit         updatedHabit = HabitFactory.CreateUpdatedData(habitRequest, habit);
            List <DayOff> dayOffList   = DayOffFactory.Create(habitRequest.DaysOff, habit.ID);

            dayOffRepository.UpdateDayOff(dayOffList, habitId);
            habitRepository.UpdateHabit(habitId, updatedHabit);
            return(ConvertFromHabitToHabitResponse(updatedHabit));
        }