public IActionResult Update(int id, [FromBody] dynamic taskTypeData) { if (!ModelState.IsValid) { return(BadRequest(new List <ErrorView> { new ErrorView { Source = "Other", Title = "", Details = "ModelState is invalid." } })); } taskTypeData.Id = id; try { var result = _service.Update(taskTypeData, this.GetUserName()); return(new ObjectResult(_mapper.Map <TaskType, TaskView>(result))); } catch (Exception e) { _logger.LogWarning($"Update methodwith parameters ({id}, {taskTypeData});\n {e}"); var errors = ExceptionsChecker.CheckTasksException(e); return(BadRequest(errors)); } }
public IActionResult Create([FromBody] TaskView taskTypeData) { if (!ModelState.IsValid) { return(BadRequest(new List <ErrorView> { new ErrorView { Source = "Other", Title = "", Details = "ModelState is invalid." } })); } try { var result = _service.Create(taskTypeData, this.GetUserName()); var locationUri = $"{Request.Host}/api/v1/odata/Tasks({result.Id})"; return(Created(locationUri, _mapper.Map <TaskType, TaskView>(result))); } catch (Exception e) { _logger.LogWarning($"Create method with parameters ({JsonConvert.SerializeObject(taskTypeData)});\n {e}"); var errors = ExceptionsChecker.CheckTasksException(e); return(BadRequest(errors)); } }
public IActionResult GetById(int id) { try { var value = _service.GetById(id); return(new ObjectResult(_mapper.Map <TaskType, TaskView>(value))); } catch (Exception e) { _logger.LogWarning($"GetById method with parameters ({id});\n {e}"); var errors = ExceptionsChecker.CheckTasksException(e); return(BadRequest(errors)); } }
public IActionResult Delete(int id) { try { var result = _service.Delete(id); return(Ok()); } catch (Exception e) { _logger.LogWarning($"Delete method with parameters ({id});\n {e}"); var errors = ExceptionsChecker.CheckTasksException(e); return(BadRequest(errors)); } }