public ActionResult Edit(int id)
        {
            var service = CreateSalesService();
            var detail  = service.GetSaleById(id);
            var model   =
                new SalesEdit
            {
                SalesId = detail.SalesId,
                CartId  = detail.CartId,
            };
            var salesService = CreateSalesService();

            ViewBag.ProductId = new SelectList(salesService.GetSales(), "CartId", "Title");
            return(View(model));
        }
        public bool UpdateSales(SalesEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Sales
                    .Single(e => e.SalesId == model.SalesId && e.OwnerId == _userId);

                entity.CartId      = model.CartId;
                entity.SalesId     = model.SalesId;
                entity.ModifiedUtc = DateTimeOffset.UtcNow;

                return(ctx.SaveChanges() == 1);
            }
        }
        public ActionResult Edit(int id, SalesEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.SalesId != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }
            var service = CreateSalesService();

            if (service.UpdateSales(model))
            {
                TempData["SaveResult"] = "Your transactions were updated.";
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "Your transaction could not be updated.");
            return(View(model));
        }