Ejemplo n.º 1
0
        private void TaskClicked(object sender, AdapterView.ItemClickEventArgs e)
        {
            var item    = items[e.Position];
            var habit   = item.Task as Habit;
            var routine = item.Task as Routine;
            var todo    = item.Task as Todo;

            if (habit != null)
            {
                presenter.MarkHabitDone(habit);
                var log = new HabitLog();
                log.HabitID   = habit.ID;
                log.Timestamp = DateTime.Today;
                adapter.IncrementItem(log);
            }
            if (routine != null)
            {
                if (adapter.WasTodayLogged(routine, routineLogs))
                {
                    return;
                }
                presenter.MarkRoutineDone(routine);
            }
            if (todo != null)
            {
                if (todo.IsDone)
                {
                    return;
                }
                presenter.MarkTodoDone(todo);
                adapter.MarkDone(todo);
            }
        }
Ejemplo n.º 2
0
        public HttpResponseMessage LogHabit(HabitLog habitLog)
        {
            MySqlConnection conn = new MySqlConnection(CONNECTION_STRING);

            try
            {
                conn.Open();

                string       rtn = "log_habit_procedure";
                MySqlCommand cmd = new MySqlCommand(rtn, conn);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@id", habitLog.ID.ToString());
                cmd.Parameters.AddWithValue("@habitId", habitLog.HabitID);
                cmd.Parameters.AddWithValue("@habitTimeStamp", habitLog.Timestamp);

                cmd.ExecuteNonQuery();
                return(base.BuildSuccessResult(HttpStatusCode.OK));
            }
            catch (Exception)
            {
                return(base.BuildErrorResult(HttpStatusCode.BadRequest, "Error creating habit!"));
            }
            finally
            {
                conn.Close();
            }
        }
Ejemplo n.º 3
0
    public static void LogBeforeSave(Habit habit, TypeUpdate typeUpdate, HabitField field, object newValue, string logDescription, MSSQLLocalDBEntities context)
    {
        var habitLog = new HabitLog
        {
            ChangeDescription = logDescription,
            DoneDate          = DateTime.Now,
            HabitId           = habit.Id
        };

        switch (field)
        {
        case HabitField.Name:
            habitLog.OldValue = habit.Name;
            break;

        case HabitField.DoneDate:
            habitLog.OldValue = habit.DoneDate?.ToString();
            break;

        case HabitField.NewRecord:
            break;

        case HabitField.DeleteRecord:
            break;

        default:
            habitLog.OldValue = "";
            break;
        }
        habitLog.NewValue = newValue.ToString();
        context.HabitLogs.Add(habitLog);
        context.SaveChanges();
    }
Ejemplo n.º 4
0
        public async Task LogHabit(HabitLog log)
        {
            var jsonData   = JsonConvert.SerializeObject(log);
            var jsonResult = await PostDataAsync("api/habit/log", jsonData);

            return;
        }
Ejemplo n.º 5
0
        public async void IncrementHabit(HabitLog log)
        {
            HabitDB habitManager = new HabitDB();
            await habitManager.LogHabit(log);

            return;
        }
        public Habit FindHabitByID(Guid habit_id, Guid user_id)
        {
            string   query     = "SELECT name, created_at FROM habit WHERE user_id = @user_id AND id = @id AND deleted_at is null";
            string   name      = "";
            DateTime timestamp = DateTime.Now;

            using (var cmd = new NpgsqlCommand(query, _connection, _transaction))
            {
                cmd.Parameters.AddWithValue("user_id", user_id);
                cmd.Parameters.AddWithValue("id", habit_id);

                NpgsqlDataReader reader = cmd.ExecuteReader();
                if (reader.Read())
                {
                    name      = reader.GetString(0);
                    timestamp = reader.GetDateTime(1);
                }
                reader.Close();
            }
            if (name == "")
            {
                throw new Exception("Habit doesnt exist");
            }
            List <Days> offDays = new List <Days>();

            query = "SELECT off_days FROM days_off WHERE habit_id = @habit_id AND deleted_at is null";
            using (var cmd = new NpgsqlCommand(query, _connection, _transaction))
            {
                cmd.Parameters.AddWithValue("habit_id", habit_id);

                NpgsqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    offDays.Add(new Days(reader.GetString(0)));
                }
                reader.DisposeAsync();
            }
            HabitLog log = FindByID(habit_id, user_id);

            return(new Habit(habit_id, name, offDays.ToArray(), user_id, timestamp, log));
        }
Ejemplo n.º 7
0
        public HttpResponseMessage GetAllHabitLogs(string username, string dateString)
        {
            var             habitLogList = new List <HabitLog>();
            MySqlConnection conn         = new MySqlConnection(CONNECTION_STRING);

            try
            {
                conn.Open();

                string       rtn = "get_all_habit_logs_procedure";
                MySqlCommand cmd = new MySqlCommand(rtn, conn);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@username", username);
                cmd.Parameters.AddWithValue("@dateRequested", dateString);

                var reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    var habitLog = new HabitLog();
                    habitLog.ID        = Guid.Parse(reader.GetString("log_id"));
                    habitLog.Timestamp = reader.GetDateTime("time_stamp");
                    habitLog.HabitID   = Guid.Parse(reader.GetString("habit_id"));
                    habitLogList.Add(habitLog);
                }
                reader.Close();
                return(base.BuildSuccessResultList(HttpStatusCode.OK, habitLogList));
            }
            catch (Exception)
            {
                return(base.BuildErrorResult(HttpStatusCode.BadRequest, "Error getting all habits!"));
            }
            finally
            {
                conn.Close();
            }
        }
Ejemplo n.º 8
0
        public override void Run()
        {
            try
            {
                var habitLog = new HabitLog();
                habitLog.ID        = Guid.NewGuid();
                habitLog.HabitID   = habit.ID;
                habitLog.Timestamp = DateTime.Today;
                habitRepository.IncrementHabit(habitLog);

                var pointsAdded = 0;
                if (habit.Difficulty == Difficulty.Easy)
                {
                    pointsAdded = 5;
                }
                if (habit.Difficulty == Difficulty.Medium)
                {
                    pointsAdded = 10;
                }
                if (habit.Difficulty == Difficulty.Hard)
                {
                    pointsAdded = 15;
                }
                if (habit.Difficulty == Difficulty.VeryHard)
                {
                    pointsAdded = 20;
                }

                userRepository.IncrementPoints(habit.Username, pointsAdded);

                mainThread.Post(() => callback.OnHabitIncremented(habit, pointsAdded));
            }
            catch (Exception)
            {
                mainThread.Post(() => callback.OnError("Error incrementing habit count. Try again."));
            }
        }
Ejemplo n.º 9
0
 public void IncrementItem(HabitLog log)
 {
     habitLogs.Add(log);
     context.RunOnUiThread(() => NotifyDataSetChanged());
 }