예제 #1
0
        public ActionResult <Habits> Log(Guid userID, Guid id)
        {
            NpgsqlConnection _connection = new NpgsqlConnection(connString);

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

            try
            {
                Habit h = repo1.FindByID(id, userID);

                repo1.AddLog(id);
                Habit habit = HabitFactory.AddLog(h);

                _connection.Close();
                return(new Habits()
                {
                    ID = habit.ID,
                    name = habit.name,
                    user_id = habit.users,
                    days = habit.daysoff,
                    Log_count = habit.Logs,
                    current_streak = habit.current_streak,
                    longest_streak = habit.longest_streak
                });
            }
            catch
            {
                return(NotFound("Failed"));
            }
        }
예제 #2
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"));
            }
        }
예제 #3
0
        public ActionResult <Habits> UpdateHabit(Guid userID, Guid id, [FromBody] RequestData data)
        {
            try
            {
                NpgsqlConnection _connection = new NpgsqlConnection(connString);
                _connection.Open();
                IHabitRepository repo1 = new HabitRepository(_connection, null);
                Habit            h     = HabitFactory.Update(id, userID, data.Name, data.days);
                repo1.UpdateHabit(h.ID, h.users, h.name, data.days);

                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("error"));
            }
        }
예제 #4
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));
        }
예제 #5
0
        public void UpdateHabit(Guid habitId, Guid userID, string newName, string[] days)
        {
            var habit   = GetSpecificHabitByIdAndUserId(habitId, userID);
            var daysoff = GetHabitDaysOff(habitId);

            DaysOffValue dv = HabitFactory.value(days);

            habit.Name      = newName;
            daysoff.daysoff = dv.value;
        }
예제 #6
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 void RegisterHabit(Guid user_id, string name, DaysOff daysOff, DateTime created_at)
        {
            Habit h = HabitFactory.CreateHabit(user_id, name, daysOff, created_at);

            SqlDataAdapter mySqlDataAdapter = DataAdapter("Habit");

            db.Habit.AddHabitRow(h.ID, h.UserID, h.Name, h.CurrentStreak, h.LongestStreak, h.LogCount, h.CreatedAt);

            mySqlDataAdapter.Update(db, "Habit");

            if (daysOff != null)
            {
                AssignDaysOff(h.ID, h.DaysOff);
            }
        }
예제 #8
0
        public void addNewHabit(string name, Guid userID, string[] days)
        {
            if (name == null)
            {
                throw new ArgumentException("name cannot be empty");
            }

            Habit h = HabitFactory.addNewHabit(userID, name);

            _context.Habits.Add(h);

            DaysOffValue dv = HabitFactory.value(days);

            if (!days.Equals(null))
            {
                DaysOff d = HabitFactory.AssignDaysOff(h.ID, dv.value);
                _context.daysOffs.Add(d);
            }
        }