Beispiel #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));
        }
Beispiel #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));
        }
        public static Habit CreateUpdatedData(HabitRequest habitRequest, Habit oldHabit)
        {
            List <DayOff> dayOffList = CreateDayOff(habitRequest.DaysOff);

            return(new Habit(oldHabit.ID, habitRequest.Name, oldHabit.UserID, oldHabit.CreatedAt, dayOffList));
        }
        public static Habit Create(HabitRequest habitRequest, Guid UserID)
        {
            List <DayOff> dayOffList = CreateDayOff(habitRequest.DaysOff);

            return(new Habit(Guid.NewGuid(), habitRequest.Name, UserID, DateTime.Now, dayOffList));
        }
 public ActionResult <HabitResponse> UpdateHabit(Guid userID, Guid id, [FromBody] HabitRequest data)
 {
     return(habitService.UpdateHabit(userID, id, data));
 }
 public ActionResult <HabitResponse> AddNewHabit(Guid userID, [FromBody] HabitRequest data)
 {
     return(habitService.CreateHabit(data, userID));
 }