public static void UpdateEntity(Dtos.Task dto, Entities.Task entity) { entity.Id = dto.Id; entity.Name = dto.Name; entity.Priority = dto.Priority; entity.Status = (Entities.TaskStatus)dto.Status; }
public async Task <ActionResult <TaskResponse> > Put([FromRoute] int id, [Bind] Dtos.Task task) { var role = User.Claims.FirstOrDefault(s => s.Type == ClaimTypes.Role)?.Value; //admin creates task if (role == null) { return(Unauthorized()); } if (id != task.Id) { return(NotFound()); } var entity = await _taskService.Find(id); if (entity == null) { return(NotFound()); } entity = _mapper.Map <Entities.Task>(task); await _taskService.Save(entity); return(Ok(entity.MapTaskResponse())); }
public async Task <ActionResult <Dtos.Task> > Create([FromBody] Dtos.Task dto) { var entity = new Entities.Task(); TaskMapper.UpdateEntity(dto, entity); await _repository.SaveAsync(entity); dto = TaskMapper.ToDto(entity); return(CreatedAtAction(nameof(Get), new { id = dto.Id }, dto)); }
public async Task <ActionResult <TaskResponse> > Post([Bind] Dtos.Task task) { var entity = _mapper.Map <Entities.Task>(task); entity.TaskStatusId = (int)Entities.TaskStatus.Type.Pending; await _taskService.Save(entity); return(CreatedAtAction(nameof(Post), entity)); }
public async Task <ActionResult> Update(Guid id, [FromBody] Dtos.Task dto) { var entity = await _repository.GetAsync(id); if (entity == null) { return(NotFound()); } TaskMapper.UpdateEntity(dto, entity); await _repository.SaveAsync(entity); dto = TaskMapper.ToDto(entity); return(Ok()); }