コード例 #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 static Habit Create(String habit_name, String[] days, Guid user, IGainer logGainer)
        {
            if (!checkDays(days))
            {
                return(null);
            }
            Habit habit = Habit.NewHabit(habit_name, user, logGainer);

            foreach (String item in days)
            {
                if ((item != "Mon") && (item != "Tue") && (item != "Wed") && (item != "Thu") && (item != "Fri") && (item != "Sat") && (item != "Sun"))
                {
                    throw new Exception("Must be 3 words!");
                }
            }
            foreach (String x in days)
            {
                habit.AddDaysOff(x);
            }

            habit.AddLogs();
            return(habit);
        }