示例#1
0
        public Habit FindByID(Guid habitID, Guid userID)
        {
            string query = "SELECT name FROM \"Habit\" WHERE id = @habitID";
            string name  = "";

            using (var cmd = new NpgsqlCommand(query, _connection, _transaction))
            {
                cmd.Parameters.AddWithValue("habitID", habitID);
                using (NpgsqlDataReader reader = cmd.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        name = reader.GetString(0);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            IGainer logGainer = new LogSuccess();
            Habit   h         = new Habit(habitID, userID, name, new Logs(getLogCount(habitID)), new Streak(getCurrentStreak(habitID), getLong(habitID)), logGainer);

            foreach (String x in getDaysOff(habitID))
            {
                h.AddDaysOff(x);
            }
            return(h);
        }
示例#2
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"));
            }
        }
示例#3
0
        public static Habit Update(Guid habitID, Guid userID, String habit_name, String[] days)
        {
            IGainer logGainer = new LogSuccess();

            if (!checkDays(days))
            {
                return(null);
            }

            Habit h = Habit.UpdateHabit(habitID, userID, habit_name, logGainer);

            h.UpdateDayOff(days);
            return(h);
        }