Exemplo n.º 1
0
        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"));
            }
        }
Exemplo n.º 2
0
        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);
            }
        }