예제 #1
0
        public IHttpActionResult PutTask(int id, TaskDTO taskDTO)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != taskDTO.TodoId)
            {
                return BadRequest();
            }

            try
            {
                taskRepo.EditTask(taskDTO);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (taskRepo.GetTaskID(id) == null)
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
예제 #2
0
 public void Create(TaskDTO taskDTO)
 {
     User user = db.Users.Find(taskDTO.User.UserId);
     Task task = mapper.taskDTOToTask(taskDTO);
     task.User = user;
     db.Tasks.Add(task);
     db.SaveChanges();
 }
예제 #3
0
 public void EditTask(TaskDTO taskDTO)
 {
     User user = db.Users.Find(taskDTO.User.UserId);
     Task task = mapper.taskDTOToTask(taskDTO);
     task.User = user;
     task.UserId = user.UserId;
     db.Entry(task).State = EntityState.Modified;
     db.SaveChanges();
 }
예제 #4
0
        public IHttpActionResult PostTask(TaskDTO taskDTO)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            taskRepo.Create(taskDTO);

            return CreatedAtRoute("DefaultApi", new { id = taskDTO.TodoId }, taskDTO);
        }
예제 #5
0
 public Task taskDTOToTask(TaskDTO taskDTO)
 {
     return Mapper.Map<Task>(taskDTO);
 }