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> 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")); } }
public static HabitResponse AddLog(Guid userID, Guid id) { NpgsqlConnection connection = Connection.GetConnection(); NpgsqlTransaction transaction = connection.BeginTransaction(); IHabitRepository repository = new HabitRepository(connection, transaction); var get = repository.Find(userID, id); if (get == null) { return(null); } repository.AddLog(userID, id); get = repository.Find(userID, id); return(get); }