public async Task <ActionResult> Post([FromBody] AccountingBookViewModel viewModel) { try { VerifyUser(); _validateService.Validate(viewModel); var model = _mapper.Map <AccountingBookModel>(viewModel); await _service.CreateAsync(model); var result = new ResultFormatter(ApiVersion, General.CREATED_STATUS_CODE, General.OK_MESSAGE).Ok(); return(Created(String.Concat(Request.Path, "/", 0), result)); } catch (ServiceValidationException e) { var result = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE).Fail(e); return(BadRequest(result)); } catch (Exception ex) { var result = new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, ex.Message) .Fail(); return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, result)); } }
public async Task <ActionResult <AccountingBookDTO> > CreateAsync([FromBody] AccountingBookCreateDTO model) { try { var accountingBook = await accountingBookService.CreateAsync(model); return(Ok(accountingBook)); } catch (ValidationException e) { return(BadRequest(e.ValidationErrors)); } }