예제 #1
0
        public Task Upsert(int id, Task task)
        {
            var existing = context.Tasks.AsNoTracking().FirstOrDefault(t => t.Id == id);

            if (existing == null)
            {
                task.DateClosed = null;
                task.DateAdded  = DateTime.Now;
                context.Tasks.Add(task);
                context.SaveChanges();
                return(task);
            }
            task.Id = id;
            if (task.TaskState == TaskState.Closed && existing.TaskState != TaskState.Closed)
            {
                task.DateClosed = DateTime.Now;
            }
            else if (existing.TaskState == TaskState.Closed && task.TaskState != TaskState.Closed)
            {
                task.DateClosed = null;
            }

            context.Tasks.Update(task);
            context.SaveChanges();
            return(task);
        }
예제 #2
0
        public Task Create(TaskPostDTO task, User addedBy)
        {
            Task taskAdd = TaskPostDTO.ToTask(task);

            task.DateClosed = null;
            task.DateAdded  = DateTime.Now;
            taskAdd.Owner   = addedBy;
            context.Tasks.Add(taskAdd);
            context.SaveChanges();
            return(taskAdd);
        }
예제 #3
0
 public static TaskGetDTO FromTask(Task task)
 {
     return(new TaskGetDTO
     {
         Title = task.Title,
         Description = task.Description,
         DateAdded = task.DateAdded,
         Deadline = task.Deadline,
         TaskImportance = task.TaskImportance,
         TaskState = task.TaskState,
         DateClosed = task.DateClosed,
         //Comments = task.Comments,
         NumberOfComments = task.Comments.Count,
     });
 }
예제 #4
0
        public IActionResult Put(int id, [FromBody] Task task)
        {
            var result = tasksService.Upsert(id, task);

            return(Ok(result));
        }