示例#1
0
        public ActionResult <Habit> Get(Guid userID, Guid id)
        {
            PostgreConnectRepo connect = new PostgreConnectRepo();
            Habit hbt = new Habit();

            if (connect.UserRepo.FindById(userID) == null)
            {
                throw new Exception("Does not have that Habit with that userID");
            }

            if (connect.HabitRepo.FindByUserId(userID, id) == null)
            {
                throw new Exception("Does not have that Habit with that userID");
            }

            _Habit foo = connect.HabitRepo.FindByUserId(userID, id);

            hbt.ID            = foo.ID;
            hbt.Name          = foo.Name;
            hbt.DaysOff       = foo.Days_Off.Days;
            hbt.CurrentStreak = foo.Logs.Current_Streak;
            hbt.LongestStreak = foo.Logs.Longest_Streak;
            hbt.LogCount      = foo.Logs.Log_Count;
            hbt.Logs          = foo.Logs.Logs;
            hbt.UserID        = foo.userID;
            hbt.CreatedAt     = foo.Created_At;
            return(hbt);
        }
示例#2
0
        public ActionResult <Habit> AddNewHabit(Guid userID, [FromBody] RequestData data)
        {
            PostgreConnectRepo connect = new PostgreConnectRepo();
            Habit hbt = new Habit();

            string[] arr = { "Mon", "Wed", "Fri" };
            if (data.DaysOff != null)
            {
                arr = data.DaysOff;
            }

            if (connect.UserRepo.FindById(userID) == null)
            {
                User us = new User(userID, "Budi");
                connect.UserRepo.Create(us);
            }

            _Habit b = _Habit.NewHabit(Guid.NewGuid(), data.Name, arr, userID, DateTime.Now);

            connect.HabitRepo.Create(b);
            connect.Commit();

            _Habit foo = connect.HabitRepo.FindByUserId(userID, b.ID);

            hbt.ID            = foo.ID;
            hbt.Name          = foo.Name;
            hbt.DaysOff       = foo.Days_Off.Days;
            hbt.CurrentStreak = foo.Logs.Current_Streak;
            hbt.LongestStreak = foo.Logs.Longest_Streak;
            hbt.LogCount      = foo.Logs.Log_Count;
            hbt.Logs          = foo.Logs.Logs;
            hbt.UserID        = foo.userID;
            hbt.CreatedAt     = foo.Created_At;
            return(hbt);
        }
示例#3
0
        public ActionResult <IEnumerable <Habit> > All(Guid userID)
        {
            PostgreConnectRepo connect = new PostgreConnectRepo();

            Habit hab = new Habit();

            List <Habit> listhab = new List <Habit>();

            if (connect.UserRepo.FindById(userID) == null)
            {
                throw new Exception("Does not have that Habit with that userID");
            }

            foreach (var el in connect.HabitRepo.GetAllHabit(userID))
            {
                hab.ID            = el.ID;
                hab.Name          = el.Name;
                hab.DaysOff       = el.Days_Off.Days;
                hab.CurrentStreak = el.Logs.Current_Streak;
                hab.LongestStreak = el.Logs.Longest_Streak;
                hab.LogCount      = el.Logs.Log_Count;
                hab.Logs          = el.Logs.Logs;
                hab.UserID        = el.userID;
                hab.CreatedAt     = el.Created_At;
                listhab.Add(hab);
            }

            return(listhab);
        }
        public void CreateThirdBadge(IBadgeCollector thirdCollect, List <_Badge> _badge, Guid user_id)
        {
            PostgreConnectRepo connect     = new PostgreConnectRepo();
            string             name        = thirdCollect.Collect()[0];
            string             description = thirdCollect.Collect()[1];
            _Badge             bdg         = new _Badge(Guid.NewGuid(), name, description, user_id, DateTime.Now);

            connect.BadgeRepo.Create(bdg);
            connect.Commit();
            _badge.Add(bdg);
        }
        public void CreateFirstBadge(IBadgeCollector firstCollect, List <_Badge> _badge, Guid user_id)
        {
            PostgreConnectRepo connect     = new PostgreConnectRepo();
            string             name        = firstCollect.Collect()[0];
            string             description = firstCollect.Collect()[1];
            _Badge             bdg         = new _Badge(Guid.NewGuid(), name, description, user_id, DateTime.Now);

            if (connect.UserRepo.FindById(user_id) != null)
            {
                connect.BadgeRepo.Create(bdg);
                connect.Commit();
            }
            _badge.Add(bdg);
        }
示例#6
0
        public ActionResult <Habit> Log(Guid userID, Guid id)
        {
            PostgreConnectRepo connect = new PostgreConnectRepo();
            Habit  hbt = new Habit();
            User   us;
            _Habit foo;

            if (connect.UserRepo.FindById(userID) == null)
            {
                throw new Exception("Does not have that Habit with that userID");
            }
            else
            {
                us = connect.UserRepo.FindById(userID);
            }

            if (connect.HabitRepo.FindByUserId(userID, id) == null)
            {
                throw new Exception("Does not have that Habit with that userID");
            }
            else
            {
                foo = connect.HabitRepo.FindByUserId(userID, id);
                foo.doHabit(foo.Days_Off.Days[0], us);
                foo.doHabit(foo.Days_Off.Days[0], us);
                foo.doHabit(foo.Days_Off.Days[0], us);
                foo.doHabit(foo.Days_Off.Days[0], us);
                foo.doHabit(foo.Days_Off.Days[0], us);

                connect.HabitRepo.UpdateLog(id, foo);
                connect.Commit();
                _Habit boo = connect.HabitRepo.FindByUserId(userID, id);
                hbt.ID            = boo.ID;
                hbt.Name          = boo.Name;
                hbt.DaysOff       = boo.Days_Off.Days;
                hbt.CurrentStreak = boo.Logs.Current_Streak;
                hbt.LongestStreak = boo.Logs.Longest_Streak;
                hbt.LogCount      = boo.Logs.Log_Count;
                hbt.Logs          = boo.Logs.Logs;
                hbt.UserID        = boo.userID;
                hbt.CreatedAt     = boo.Created_At;
            }
            return(hbt);
        }
示例#7
0
        public ActionResult <Habit> UpdateHabit(Guid userID, Guid id, [FromBody] RequestData data)
        {
            PostgreConnectRepo connect = new PostgreConnectRepo();
            Habit hbt = new Habit();

            if (connect.UserRepo.FindById(userID) == null)
            {
                throw new Exception("Does not have that Habit with that userID");
            }

            if (connect.HabitRepo.FindByUserId(userID, id) == null)
            {
                throw new Exception("Does not have that Habit with that userID");
            }

            if (data.DaysOff == null)
            {
                connect.HabitRepo.UpdateName(id, data.Name, userID);
                connect.Commit();
            }
            else
            {
                connect.HabitRepo.UpdateNameAndDays(id, data.Name, data.DaysOff, userID);
                connect.Commit();
            }

            _Habit foo = connect.HabitRepo.FindByUserId(userID, id);

            hbt.ID            = foo.ID;
            hbt.Name          = foo.Name;
            hbt.DaysOff       = foo.Days_Off.Days;
            hbt.CurrentStreak = foo.Logs.Current_Streak;
            hbt.LongestStreak = foo.Logs.Longest_Streak;
            hbt.LogCount      = foo.Logs.Log_Count;
            hbt.Logs          = foo.Logs.Logs;
            hbt.UserID        = foo.userID;
            hbt.CreatedAt     = foo.Created_At;
            return(hbt);
        }
        public ActionResult <IEnumerable <Badge> > All(Guid userID)
        {
            PostgreConnectRepo connect = new PostgreConnectRepo();
            List <Badge>       badg    = new List <Badge>();

            if (connect.UserRepo.FindById(userID) == null)
            {
                throw new Exception("Does not have that badge with that userID");
            }

            User user_people = connect.UserRepo.FindById(userID);

            if (connect.BadgeRepo.FindByUserId(userID) == null)
            {
                throw new Exception("Does not have that badge with that userID");
            }

            foreach (var el in connect.BadgeRepo.GetAllBadge(userID))
            {
                badg.Add(new Badge(el.ID, el.Name, el.Description, el.User_Id, el.Created_At));
            }

            return(badg);
        }