public async Task <IActionResult> PutReceiptDetail(int id, ReceiptDetailViewModel receiptDetail) { if (receiptDetail.Id != id) { throw new Exception(string.Format("Id và Id của phiếu thu không giống nhau!")); } try { await Task.Run(() => { receiptDetail.DateModified = DateTime.Now; _receiptDetailService.Update(receiptDetail); _receiptDetailService.SaveChanges(); return(Ok()); }); } catch (DbUpdateConcurrencyException) { if (!ReceiptDetailExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult Edit(ReceiptDetailViewModel model) { if (ModelState.IsValid) { if (Request["Submit"] == "Save") { var ReceiptDetail = ReceiptDetailRepository.GetReceiptDetailById(model.Id); AutoMapper.Mapper.Map(model, ReceiptDetail); ReceiptDetail.ModifiedUserId = WebSecurity.CurrentUserId; ReceiptDetail.ModifiedDate = DateTime.Now; ReceiptDetailRepository.UpdateReceiptDetail(ReceiptDetail); TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.UpdateSuccess; return(RedirectToAction("Index")); } return(View(model)); } return(View(model)); //if (Request.UrlReferrer != null) // return Redirect(Request.UrlReferrer.AbsoluteUri); //return RedirectToAction("Index"); }
public static void updateReceiptDetail(this ReceiptDetail receiptDetail, ReceiptDetailViewModel receiptDetailVm) { receiptDetail.ReceiptID = receiptDetailVm.ReceiptID; receiptDetail.ProductID = receiptDetailVm.ProductID; receiptDetail.Quantity = receiptDetailVm.Quantity; receiptDetail.Price = receiptDetailVm.Price; }
public async Task <IActionResult> Detail(int id) { ViewBag.NewBreadcrumItem = new BreadcrumComponentsModel { ItemController = "receipt", ItemAction = "detail", ItemTitle = "dettaglio" }; ReceiptDetailViewModel receipt = await receiptService.GetReceiptAsync(id); return(View(receipt)); }
public bool Update(ReceiptDetailViewModel receiptDetailVm) { try { var receipt = Mapper.Map <ReceiptDetailViewModel, ReceiptDetail>(receiptDetailVm); _receiptDetailRepository.Update(receipt); return(true); } catch { return(false); } }
public bool Add(ReceiptDetailViewModel receiptDetailVm) { try { var receiptDetail = Mapper.Map <ReceiptDetailViewModel, ReceiptDetail>(receiptDetailVm); _receiptDetailRepository.Add(receiptDetail); return(true); } catch { return(false); } }
public ReceiptDetailPage() { InitializeComponent(); var receipt = new Receipt { Name = "#1-1000", TransactionDate = DateTime.Now, Total = 1800 }; viewModel = new ReceiptDetailViewModel(receipt); BindingContext = viewModel; }
public ActionResult Create(ReceiptDetailViewModel model) { if (ModelState.IsValid) { var ReceiptDetail = new ReceiptDetail(); AutoMapper.Mapper.Map(model, ReceiptDetail); ReceiptDetail.IsDeleted = false; ReceiptDetail.CreatedUserId = WebSecurity.CurrentUserId; ReceiptDetail.ModifiedUserId = WebSecurity.CurrentUserId; ReceiptDetail.AssignedUserId = WebSecurity.CurrentUserId; ReceiptDetail.CreatedDate = DateTime.Now; ReceiptDetail.ModifiedDate = DateTime.Now; ReceiptDetailRepository.InsertReceiptDetail(ReceiptDetail); TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.InsertSuccess; return(RedirectToAction("Index")); } return(View(model)); }
public async Task <ActionResult <ReceiptDetailViewModel> > PostReceiptDetail(ReceiptDetailViewModel receiptDetail) { if (receiptDetail != null) { try { await Task.Run(() => { receiptDetail.DateCreated = DateTime.Now; _receiptDetailService.Add(receiptDetail); _receiptDetailService.SaveChanges(); return(Ok("Thêm phiếu chi thành công!")); }); } catch { throw new Exception(string.Format("Lỗi khi thêm dữ liệu")); } } return(CreatedAtAction("PostReceipt", new { id = receiptDetail.Id }, receiptDetail)); }
public ReceiptDetailViewModel GetReceipt(int id) { string[,] randomTransactionMethod = new string[2, 2]; randomTransactionMethod[0, 0] = "credit-card-solid.svg"; randomTransactionMethod[0, 1] = "Bancomat"; randomTransactionMethod[1, 0] = "coins-solid.svg"; randomTransactionMethod[1, 1] = "Contanti"; var rand = new Random(); var randomPrice = Convert.ToDecimal(rand.NextDouble() * 10 * 10); var ramdomMethodNumber = rand.Next(0, 2); var receipt = new ReceiptDetailViewModel { Id = id, TransactionMethod = new TransactionMethods(randomTransactionMethod[ramdomMethodNumber, 0], randomTransactionMethod[ramdomMethodNumber, 1]), Location = "Via S.Bernardino - BERGAMO", DateTime = new DateTime(2020, 1, 22, 12, 34, 0), StoreItems = new List <StoreItem>(), Price = new Money(Enums.Currency.EUR, rand.NextDouble() > 0.5 ? randomPrice : randomPrice - 1), ReceiptTemplate = new ReceiptTemplate("pago-bancomat.jpg", "PagoBancomat"), OrigImagePath = ramdomMethodNumber == 0 ? "scontrino-mock-orig.jpg" : null, ElabImagePath = ramdomMethodNumber == 1 ? "scontrino-mock-elab.jpg" : null }; var randomListItems = rand.Next(1, 20); for (int j = 0; j < randomListItems; j++) { randomPrice = Convert.ToDecimal(rand.NextDouble() * 10 * 10); StoreItem storeItem = new StoreItem(); storeItem.Amount = rand.NextDouble() > 0.5 ? randomPrice : randomPrice - 1; receipt.StoreItems.Add(storeItem); } ; return(receipt); }
public ActionResult Edit(int?Id) { var ReceiptDetail = ReceiptDetailRepository.GetReceiptDetailById(Id.Value); if (ReceiptDetail != null && ReceiptDetail.IsDeleted != true) { var model = new ReceiptDetailViewModel(); AutoMapper.Mapper.Map(ReceiptDetail, model); if (model.CreatedUserId != Helpers.Common.CurrentUser.Id && Helpers.Common.CurrentUser.UserTypeId != 1) { TempData["FailedMessage"] = "NotOwner"; return(RedirectToAction("Index")); } return(View(model)); } if (Request.UrlReferrer != null) { return(Redirect(Request.UrlReferrer.AbsoluteUri)); } return(RedirectToAction("Index")); }
public ReceiptDetailPage(ReceiptDetailViewModel viewModel) { InitializeComponent(); BindingContext = this.viewModel = viewModel; }
public ViewResult Create() { var model = new ReceiptDetailViewModel(); return(View(model)); }