public IActionResult OnPost(int?id) { //input model to supplier //Update in repo if (id.HasValue) { var supplier = _supplierRepo.GetById(id.Value); supplier.CompanyName = Input.CompanyName; supplier.Balance = Input.Balance; _supplierRepo.Update(supplier); } else { if (!ModelState.IsValid) { return(Page()); } var supplier = new NoTricks.Data.Models.Supplier { CompanyName = Input.CompanyName, Balance = Input.Balance }; _supplierRepo.Insert(supplier); } return(RedirectToPage("Index")); }
public IActionResult OnGetPayout(int supplierId) { var supplier = _supplierRepo.GetById(supplierId); if (supplier == null) { return(NotFound()); } //Create payout and zero out supplier balance var payout = new SupplierPayout { Amount = supplier.Balance, PayedAt = DateTime.UtcNow, StaffId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value), SupplierId = supplier.Id }; supplier.Balance = 0; //This should be in a tranaction, but we need to ensure the payment is added before we update the balance. if (_supplierPayoutRepo.Insert(payout) != 0) { _supplierRepo.Update(supplier); } return(RedirectToPage()); }
public ActionResult Edit(SupplierVM sup) { try { if (!ModelState.IsValid) { return(View(sup)); } var supplier = _mapper.Map <Supplier>(sup); var isSuccess = _repo.Update(supplier); if (!isSuccess) { ModelState.AddModelError("", "Check for Information"); return(View(sup)); } return(RedirectToAction(nameof(Index))); } catch { ModelState.AddModelError("", "Check for Information"); return(View(sup)); } }