Пример #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));
        }