Example #1
0
        public ActionResult <Habits> AddNewHabit(Guid userID, [FromBody] RequestData data)
        {
            NpgsqlConnection _connection = new NpgsqlConnection(connString);

            _connection.Open();
            IHabitRepository repo1 = new HabitRepository(_connection, null);

            IGainer logGainer = new LogSuccess();

            try
            {
                Habit h = HabitFactory.Create(data.Name, data.days, userID, logGainer);

                repo1.CreateHabit(h, data.days);

                repo1.AddLog(h.ID);

                repo1.AddStreak(h.ID, h.getStreak());
                return(new Habits()
                {
                    ID = h.ID,
                    name = h.name,
                    user_id = h.users,
                    Log_count = h.Logs,
                    days = h.daysoff,
                    current_streak = h.current_streak,
                    longest_streak = h.longest_streak
                });
            }
            catch
            {
                return(NotFound("user not found"));
            }
        }
Example #2
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));
        }