public bool UpdateTrans(TransactionUpdate model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .BBShopTransactions .Single(e => e.TransactionID == model.TransactionID); entity.CustomerID = model.CustomerID; entity.ProductID = model.ProductID; entity.ModifiedUtc = DateTimeOffset.UtcNow; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id) { var detail = _service.GetTransByID(id); var model = new TransactionUpdate { TransactionID = detail.TransactionID, FullName = detail.FullName, ProductName = detail.ProductName }; ProductService prodSvc; CustomerService custSvc; ViewInfo(out prodSvc, out custSvc); ViewBag.CustomerID = new SelectList(custSvc.GetCustomer(), "CustomerID", "FullName"); ViewBag.ProductID = new SelectList(prodSvc.GetProducts(), "ProductID", "ProductName"); return(View(model)); }
public ActionResult Edit(int id) { _tranSvc = GetServices(); var detail = _tranSvc.GetTransByID(id); var model = new TransactionUpdate { TransactionID = detail.TransactionID, FullName = detail.FullName, ProductName = detail.ProductName }; _prodSvc = GetProductService(); _custSvc = GetCustomerService(); ViewBag.CustomerID = new SelectList(_custSvc.GetCustomer(), "CustomerID", "FullName"); ViewBag.ProductID = new SelectList(_prodSvc.GetProducts(), "ProductID", "ProductName"); return(View(model)); }
public ActionResult Edit(int id, TransactionUpdate model) { if (!ModelState.IsValid) { return(View(model)); } if (model.TransactionID != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } if (_service.UpdateTrans(model)) { TempData["SaveResult"] = "Your transaction was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your transaction could not be updated."); return(View(model)); }
public IActionResult Put(int id, [FromBody] TransactionUpdate transactionUpdate) { var transaction = Service.Get(id); if (transaction == null) { return(NotFound()); } transaction.AccountId = transactionUpdate.AccountId; transaction.CategoryId = transactionUpdate.CategoryId; transaction.Description = transactionUpdate.Description; transaction.DateTime = transactionUpdate.DateTime; transaction.Amount = transactionUpdate.Amount; transaction.Fee = transactionUpdate.Fee; transaction.Tags = transactionUpdate.Tags; Service.Update(transaction); return(Ok(transaction)); }