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 <IActionResult> Put([FromRoute] int id, [FromBody] AccountingBookViewModel viewModel) { try { VerifyUser(); _validateService.Validate(viewModel); if (id != viewModel.Id) { var result = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE).Fail(); return(BadRequest(result)); } var model = _mapper.Map <AccountingBookModel>(viewModel); await _service.UpdateAsync(id, model); return(NoContent()); } catch (ServiceValidationException e) { var result = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE).Fail(e); return(BadRequest(result)); } catch (Exception e) { var result = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, e.Message).Fail(); return(StatusCode(General.BAD_REQUEST_STATUS_CODE, result)); } }
public ActionResult Index(int page = 1, string ParaDate = "") { IPagedList <AccountingBookDisplay> resource; int currentPage = page < 1 ? 1 : page; DateTime beginDate; if (DateTime.TryParseExact(ParaDate, "yyyy/MM", CultureInfo.InvariantCulture, DateTimeStyles.None, out beginDate)) { DateTime endDate = beginDate.AddMonths(1); resource = _accbookSvc.AccBookVMLookup(currentPage, pageSize, beginDate, endDate); } else { resource = _accbookSvc.AccBookVMLookup(currentPage, pageSize, null, null); } AccountingBookViewModel result = new AccountingBookViewModel { Date = DateTime.Now, AccountBookList = resource }; return(View(result)); }
public ActionResult Index_Add(AccountingBookViewModel item, int page = 1) { int currentPage = page < 1 ? 1 : page; if (ModelState.IsValid) { _accbookSvc.AccBookInsert(item); _accbookSvc.Save(); } var result = _accbookSvc.AccBookVMLookup(currentPage, pageSize, null, null); return(PartialView("_IndexPartial", result)); }
public void AccBookInsert(AccountingBookViewModel item) { try { AccountBook accountBook = new AccountBook { Id = Guid.NewGuid(), Amounttt = item.Amount, Categoryyy = (int)item.Category, Dateee = item.Date, Remarkkk = item.Memo }; _accRep.Create(accountBook); } catch { throw; } }