Exemplo n.º 1
0
 public ActionResult <Habit> UpdateHabit(Guid userID, Guid id, [FromBody] RequestData data)
 {
     using (var uw = new PostgresUnitOfWork(connString))
     {
         if (IsUserIdValid(userID) != false)
         {
             Habit h = uw.HabitRepo.FindById(id);
             if (h == null || h.UserID != userID)
             {
                 return(NotFound("habit not found"));
             }
             else
             {
                 uw.HabitRepo.Update(h, data.Name, data.DaysOff);
                 h = uw.HabitRepo.FindById(id);
                 uw.Commit();
                 return(h);
             }
         }
         else
         {
             return(NotFound("user not found"));
         }
     }
 }
Exemplo n.º 2
0
 public ActionResult <Habit> Log(Guid userID, Guid id)
 {
     using (var uw = new PostgresUnitOfWork(connString))
     {
         if (IsUserIdValid(userID) != false)
         {
             DateTime curentDate = DateTime.Now;
             Habit    h          = uw.HabitRepo.FindById(id);
             if (h == null || h.UserID != userID)
             {
                 return(NotFound("habit not found"));
             }
             else
             {
                 uw.HabitRepo.AddLog(h, curentDate);
                 Habit newHabit = uw.HabitRepo.FindById(id);
                 uw.Commit();
                 return(newHabit);
             }
         }
         else
         {
             return(NotFound("user not found"));
         }
     }
 }
 public void createNewDominatingBadge()
 {
     using (var uw = new PostgresUnitOfWork(connString))
     {
         Badge b = new Badge("Dominating", "4+ streak");
         uw.BadgeRepo.Create(b);
         uw.Commit();
         Assert.Equal("Dominating", b.Name);
     }
 }
 public void LogTest()
 {
     using (var uw = new PostgresUnitOfWork(connString))
     {
         for (int i = 0; i < 1; i++)
         {
             DateTime curentDate = DateTime.Now.AddDays(i + 3);
             Habit    h          = uw.HabitRepo.FindById(id);
             uw.HabitRepo.AddLog(h, curentDate);
         }
         uw.Commit();
         Badge[] badges = uw.BadgeRepo.GetAllBadgeByUserId(user_id);
         Assert.Equal("Dominating", badges[0].Name);
     }
 }
Exemplo n.º 5
0
 public ActionResult <Habit> AddNewHabit(Guid userID, [FromBody] RequestData data)
 {
     using (var uw = new PostgresUnitOfWork(connString))
     {
         if (IsUserIdValid(userID) != false)
         {
             Habit h = new Habit(data.Name, data.DaysOff, userID);
             uw.HabitRepo.Create(h);
             uw.Commit();
             if (h == null)
             {
                 return(NotFound("habit not found"));
             }
             else
             {
                 return(h);
             }
         }
         else
         {
             return(NotFound("user not found"));
         }
     }
 }
Exemplo n.º 6
0
 public ActionResult <Habit> DeleteHabit(Guid userID, Guid id)
 {
     using (var uw = new PostgresUnitOfWork(connString))
     {
         if (IsUserIdValid(userID) != false)
         {
             Habit h = uw.HabitRepo.FindById(id);
             if (h == null || h.UserID != userID)
             {
                 return(NotFound("habit not found"));
             }
             else
             {
                 h = uw.HabitRepo.Delete(h);
                 uw.Commit();
                 return(h);
             }
         }
         else
         {
             return(NotFound("user not found"));
         }
     }
 }