public async Task <IActionResult> Put([FromRoute] int id, [FromBody] AccountingCategory model) { try { VerifyUser(); _validateService.Validate(model); if (id != model.Id) { var response = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE).Fail(); return(BadRequest(response)); } await _service.UpdateModel(id, model); return(NoContent()); } catch (ServiceValidationException e) { var response = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE).Fail(e); return(BadRequest(response)); } catch (Exception e) { var response = new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message).Fail(); return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, response)); } }
public AccountingCategory GetNewData() { Guid guid = Guid.NewGuid(); AccountingCategory model = new AccountingCategory() { Code = "Code", Name = "Name", AccountingLayoutIndex = 1, }; return(model); }
public async Task <ActionResult> Post([FromBody] AccountingCategory model) { try { VerifyUser(); _validateService.Validate(model); await _service.CreateModel(model); var response = new ResultFormatter(ApiVersion, General.CREATED_STATUS_CODE, General.OK_MESSAGE).Ok(); return(Created(string.Concat(Request.Path, "/", 0), response)); } catch (ServiceValidationException e) { var response = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE).Fail(e); return(BadRequest(response)); } catch (Exception e) { var response = new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message).Fail(); return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, response)); } }