Пример #1
0
        public bool UpdateTrans(TransUpdate model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Transactions
                    .Single(e => e.TransactionID == model.TransactionID);
                entity.CustomerID  = model.CustomerID;
                entity.ProductID   = model.ProductID;
                entity.ModifiedUtc = DateTimeOffset.UtcNow;

                return(ctx.SaveChanges() == 1);
            }
        }
Пример #2
0
        public ActionResult Edit(int id)
        {
            var detail = _service.GetTransByID(id);
            var model  =
                new TransUpdate
            {
                TransactionID = detail.TransactionID,
                CustomerName  = detail.CustomerName,
                ProductName   = detail.ProductName
            };
            ProductService  prodSvc;
            CustomerService custSvc;

            ViewInfo(out prodSvc, out custSvc);
            ViewBag.CustomerID = new SelectList(custSvc.GetCustomer(), "CustomerID", "CustomerName");
            ViewBag.ProductID  = new SelectList(prodSvc.GetProducts(), "ProductID", "ProductName");
            return(View(model));
        }
Пример #3
0
        public ActionResult Edit(int id, TransUpdate 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));
        }