Beispiel #1
0
        public void AddCompletedTask(AddCompletedTask task)
        {
            var sql = @"
                insert into TasksCompleted
                ([Description], DateCreated, Category, UserID)
                values (@Description, @DateCreated, @Category, @UserId)";

            using (var conn = _dbConnectionProvider.GetOpenWsidnConnection())
            {
                conn.Execute(sql, task);
            }
        }
Beispiel #2
0
        public IActionResult Complete(int id)
        {
            var taskToComplete = _taskCommands.GetTask(id, _userId);

            if (taskToComplete == null)
            {
                return(new NotFoundResult());
            }

            //Save the completed task to the completed tasks table
            var completedTask = new AddCompletedTask
            {
                Description = taskToComplete.Description,
                DateCreated = taskToComplete.DateCreated,
                Category    = taskToComplete.Category,
                UserId      = _userId
            };

            _taskCommands.AddCompletedTask(completedTask);

            //Check if the task is repeating, if not, delete it
            if (taskToComplete.IntervalByHour == 0)
            {
                _taskCommands.DeleteTaskTodo(id, _userId);
            }
            //if the task IS repeating, update the DateStart field to the future (vs. right now)
            else
            {
                _taskCommands
                .UpdateTaskDateStart(
                    id,
                    DateTime.Now.AddHours(taskToComplete.IntervalByHour),
                    _userId
                    );
            }

            return(new LocalRedirectResult(_homeRedirectUrl));
        }