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")); } }
public ActionResult <Habits> DeleteHabit(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.DeleteHabit(id, userID); return(new Habits() { ID = h.ID, name = h.name, user_id = h.users, days = h.daysoff, Log_count = h.Logs, current_streak = h.current_streak, longest_streak = h.longest_streak }); } catch { return(NotFound("Failed!")); } }
public ActionResult <IEnumerable <Habits> > All(Guid userID) { NpgsqlConnection _connection = new NpgsqlConnection(connString); _connection.Open(); IHabitRepository repo1 = new HabitRepository(_connection, null); List <Habits> habits = new List <Habits>(); List <Guid> userHabit = new List <Guid>(); List <Habit> habit = new List <Habit>(); try { foreach (Guid x in repo1.cekUser(userID)) { userHabit.Add(x); } foreach (Guid y in userHabit) { habit.Add(repo1.FindByID(y, userID)); } foreach (Habit x in habit) { Habits ht = new Habits() { ID = x.ID, name = x.name, user_id = x.users, days = x.daysoff, Log_count = x.Logs, current_streak = x.current_streak, longest_streak = x.longest_streak }; habits.Add(ht); } return(habits); } catch { return(NotFound("user not found")); } }