示例#1
0
        public ActionResult BuySlipReport(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BuySlip buySlip = db.BuySlips.Find(id);

            if (buySlip == null)
            {
                TempData["message"] = "ویرایش انجام شد";
                TempData["success"] = "false";
                return(RedirectToAction(actionName: "Index", controllerName: "BuySlips"));
            }
            BuySlipViewModel bsViewModel = new BuySlipViewModel()
            {
                TotalPrice    = db.BuySlipItems.Where(x => x.BuySlipId == id).Sum(x => x.Price * x.Quantity),
                Id            = buySlip.Id,
                DateCreation  = buySlip.DateCreation,
                DeliveryMan   = buySlip.DeliveryMan,
                Description   = buySlip.Description,
                EntrySlipType = buySlip.EntrySlipType.Name,
                Supplier      = buySlip.Supplier.FirstName + " " + buySlip.Supplier.LastName,
                UserName      = buySlip.ApplicationUser.UserName,
                AboutFotter   = db.Abouts.FirstOrDefault(),
                BuySlipItems  = db.BuySlipItems.Where(x => x.BuySlipId == id)
                                .Select(x => new BuySlipItemViewModel()
                {
                    Description     = x.Description,
                    Price           = x.Price,
                    Id              = x.Id,
                    ProductName     = x.Product.Name,
                    PriceInQuantity = x.Price * x.Quantity,
                    Quantity        = x.Quantity
                }).ToList()
            };

            if (buySlip == null)
            {
                return(HttpNotFound());
            }

            ViewBag.SupplierId   = new SelectList(db.Suppliers, "Id", "LastName", buySlip.SupplierId);
            Session["BuySlipId"] = id;
            return(View(bsViewModel));
        }
        // GET: BuySlips/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BuySlip buySlip = db.BuySlips.Find(id);

            BuySlipViewModel bsViewModel = new BuySlipViewModel()
            {
                Id              = buySlip.Id,
                DateCreation    = buySlip.DateCreation,
                DeliveryMan     = buySlip.DeliveryMan,
                Description     = buySlip.Description,
                EntrySlipTypeId = buySlip.EntrySlipTypeId,
                SupplierId      = buySlip.SupplierId,
                AppUserId       = buySlip.AppUserId,
                TotalPrice      = db.BuySlipItems.Where(x => x.BuySlipId == id).Sum(x => x.Price * x.Quantity),
                BuySlipItems    = db.BuySlipItems.Where(x => x.BuySlipId == id)
                                  .Select(x => new BuySlipItemViewModel()
                {
                    Description     = x.Description,
                    Price           = x.Price,
                    Id              = x.Id,
                    ProductName     = x.Product.Name,
                    PriceInQuantity = x.Price * x.Quantity,
                    Quantity        = x.Quantity
                }).ToList()
            };

            if (buySlip == null)
            {
                return(HttpNotFound());
            }

            ViewBag.SupplierId      = new SelectList(db.Suppliers, "Id", "LastName", buySlip.SupplierId);
            ViewBag.EntrySlipTypeId = new SelectList(db.EntrySlipTypes, "Id", "Name", buySlip.EntrySlipTypeId);
            Session["BuySlipId"]    = id;
            return(View(bsViewModel));
        }