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 <Badges> > All(Guid userID) { NpgsqlConnection _connection = new NpgsqlConnection(connString); _connection.Open(); IHabitRepository repo1 = new HabitRepository(_connection, null); List <Guid> badgeID = new List <Guid>(); List <Badge> badge = new List <Badge>(); List <Badges> badges = new List <Badges>(); foreach (Guid x in repo1.GetAllBadge(userID)) { badgeID.Add(x); } foreach (Guid y in badgeID) { badge.Add(repo1.FindBadge(userID, y)); } foreach (Badge z in badge) { Badges bg = new Badges() { ID = z.ID, name = z.name, description = z.description, user_id = z.users, created_at = z.created_at }; badges.Add(bg); } return(badges); }
public void ValidateBadgeAssignment() { IEnumerable <Log> logs = HabitRepository.GetLogDataByID(_habit.ID, _habit.UserID); IEnumerable <Badge_Assignment> AssignedBadges = Badge_AssignmentRepository.GetAssignedBadgeByUserID(_habit.UserID); List <string> badges = new List <string>(); if (AssignedBadges.Count() < 3) { foreach (Badge_Assignment bd in AssignedBadges) { badges.Add(bd._Badge.Name); } if (!badges.Contains("Dominating") && CheckDominating()) { Badge_AssignmentRepository.SaveBadgeAssignmentData(_habit.UserID, "Dominating", _log.Date_Log); } if (!badges.Contains("Workaholic") && CheckWorkaholic()) { Badge_AssignmentRepository.SaveBadgeAssignmentData(_habit.UserID, "Workaholic", _log.Date_Log); } if (!badges.Contains("Epic Comeback") && CheckEpic(_habit, logs)) { Badge_AssignmentRepository.SaveBadgeAssignmentData(_habit.UserID, "Epic Comeback", _log.Date_Log); } } }
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 void LogIn(DateTime Date_Log) { if (LogCount > 0) { IEnumerable <Log> logs = HabitRepository.GetLogDataByID(ID, UserID); if (logs.Count() > 0 && (Date_Log.Date - logs.ElementAt(logs.Count() - 1).Date_Log.Date).Days == 1) { CurrentStreak++; } else if (!Date_Log.Date.Equals(logs.ElementAt(logs.Count() - 1).Date_Log.Date)) { CurrentStreak = 1; } } else { CurrentStreak = 1; } if (LongestStreak < CurrentStreak) { LongestStreak = CurrentStreak; HabitRepository.UpdateLongestStreak(ID, LongestStreak); } HabitRepository.UpdateCurrentStreak(ID, CurrentStreak); HabitRepository.UpdateLogCount(ID, ++LogCount); Log log = new Log(ID, UserID, Date_Log); HabitRepository.SaveLogData(log); events.Add(new HabitLoggedInEvent(this, log)); }
public DeleteHabitInteractorImpl(Executor taskExecutor, MainThread mainThread, DeleteHabitInteractorCallback callback, HabitRepository habitRepository, Habit habit) : base(taskExecutor, mainThread) { this.callback = callback; this.habitRepository = habitRepository; this.habit = habit; }
public ActionResult <Habit> AddNewHabit(Guid user_id, [FromBody] RequestData data) { DaysOff daysoff = new DaysOff(data.DaysOff); HabitRepository.RegisterHabit(user_id, data.Name, daysoff, DateTime.Now); return(Ok(HabitRepository.GetNewestHabit(user_id))); }
public bool CheckWorkaholic() { int streak = 0; IEnumerable <Habit> hList = HabitRepository.GetHabitByUserId(_habit.UserID); foreach (Habit hb in hList) { IEnumerable <Log> logList = HabitRepository.GetLogDataByID(hb.ID, hb.UserID); Log temp = null; foreach (Log l in logList) { if (streak == 0) { temp = l; } else if ((l.Date_Log.Date - temp.Date_Log.Date).Days != 0) { continue; } foreach (string s in hb.DaysOff.value) { if (l.Date_Log.DayOfWeek.ToString().StartsWith(s)) { ++streak; if (streak >= 10) { return(true); } } } } } return(false); }
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")); } }
public HabitsController( BaseTranslator <Habit, HabitDto> translator, BaseValidator <Habit> validator, HabitRepository repo, ValidationErrorTranslator errorTranslator) : base("GetHabit", translator, validator, repo, errorTranslator) { }
public ActionResult <Habit> Log(Guid user_id, Guid id) { Habit h = HabitRepository.GetHabitByID(id, user_id); h.LogIn(DateTime.Now); return(Ok(h)); }
public CreateHabitInteractorImpl(Executor taskExecutor, MainThread mainThread, CreateHabitInteractorCallback callback, HabitRepository habitRepository, string username, Habit habit) : base(taskExecutor, mainThread) { this.callback = callback; this.habitRepository = habitRepository; this.habit = habit; this.username = username; }
public IncrementHabitInteractorImpl(Executor taskExecutor, MainThread mainThread, IncrementHabitInteractorCallback callback, HabitRepository habitRepository, UserRepository userRepository, Habit habit) : base(taskExecutor, mainThread) { this.callback = callback; this.habitRepository = habitRepository; this.userRepository = userRepository; this.habit = habit; }
public ActionResult <Habit> Get(Guid user_id, Guid id) { Habit h = HabitRepository.GetHabitByID(id, user_id); if (h != null) { return(Ok(h)); } return(NotFound("habit not found")); }
public ActionResult <IEnumerable <Habit> > All(Guid user_id) { var UserHabits = HabitRepository.GetHabitByUserId(user_id); if (UserHabits != null) { return(Ok(UserHabits)); } return(NotFound("user not found")); }
public OverviewPresenterImpl(Executor executor, MainThread mainThread, OverviewView view, HabitRepository habitRepository, RoutineRepository routineRepository, TodoRepository todoRepository, UserRepository userRepository, string username, string password) : base(executor, mainThread) { this.view = view; this.habitRepository = habitRepository; this.userRepository = userRepository; this.routineRepository = routineRepository; this.todoRepository = todoRepository; this.username = username; this.password = password; }
public async void CreateScheduleTest() { var taskRepository = new TaskRepository(); var habitRepository = new HabitRepository(); var service = new ScheduleService(taskRepository, habitRepository); Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); await service.CreateSchedule("eda1df41-a346-48dc-81ea-1f3288fcd58a", "d6a79a07-8f98-40fd-b1c2-d6269b3d6918"); Assert.True(true); }
public ActionResult <Habit> UpdateHabit(Guid user_id, Guid id, [FromBody] RequestData data) { Habit h = HabitRepository.GetHabitByID(id, user_id); if (h != null) { DaysOff daysoff = new DaysOff(data.DaysOff); HabitRepository.UpdateHabitData(id, user_id, data.Name, daysoff); return(Ok(h)); } return(NotFound("habit not found")); }
public GetTaskContainerInteractorImpl(Executor taskExecutor, MainThread mainThread, GetTaskContainerCallback callback, HabitRepository habitRepository, RoutineRepository routineRepository, TodoRepository todoRepository, string username, string password, DayOfWeek dayOfWeek, bool includeAllRoutines = false, bool includeLogs = false) : base(taskExecutor, mainThread) { this.callback = callback; this.habitRepository = habitRepository; this.routineRepository = routineRepository; this.todoRepository = todoRepository; this.username = username; this.password = password; this.dayOfWeek = dayOfWeek; this.includeAllRoutines = includeAllRoutines; this.includeLogs = includeLogs; }
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); }
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")); } }
public override void Update(HabitResult e) { Success ev = e as Success; if (ev == null) { return; } NpgsqlConnection _connection = new NpgsqlConnection(connString); _connection.Open(); IHabitRepository repo1 = new HabitRepository(_connection, null); if (repo1.getLastLog(ev._habit.ID) != 0) { repo1.AddStreak(ev._habit.ID, _gainer.Gain()); repo1.GiveBadge(ev._habit.ID); } else { repo1.AddStreak(ev._habit.ID, 0); } }
public HabitCompletionValidator(HabitRepository habitRepo) { _habitRepo = habitRepo; }