Пример #1
0
        // GET: /Order/Create/CustomerID
        public ActionResult Create(int id, int page = 1 ,string searchTerm = null)
        {
            CustomerOrderVM _viewmodel = new CustomerOrderVM();

            var _customer = db.Customers.Find(id);

            _viewmodel.CustomerId=_customer.CustomerID;

            ViewBag.StoreId = new SelectList(db.Stores, "StoreId", "StoreName");
            ViewBag.OrderTypeId = new SelectList(db.OrderTypes, "OrderTypeId", "OrderTypeName");
            ViewBag.EmployeeId = new SelectList(db.Employees, "EmployeeId", "EmployeeName");

            //List of Product Order Detail

            //Joining the three tables
            /*
            var qry = db.Orders
                .Join(db.OrderDetails, O => O.OrderId, er => er.OrderId, (O, er) => new { Order = O, OrderDetail = er })
                .Join(db.Products, Or => Or.OrderDetail.ProductId, P => P.ProductId, (P, OR) => new { Product = P, OrderDetail = OR })
                .ToList();
            */

            var qry = db.Products
                .Include(p => p.producttype)
                .ToList();

            var _detailResult = new List<OrderDetailListVM>();

            var qry3 = db.ProductLensDetails
                .OrderBy(p => p.ProductId)
                .Where(c => searchTerm == null || c.Product.ProductSKU.Equals(searchTerm) || c.Product.ProductName.Contains(searchTerm));

            var _lensviewmodel = new List<AddLensVM>();

            foreach (ProductLensDetail lens in qry3)
            {
                var _lens = new AddLensVM()
                {
                    ProductId = lens.ProductId,
                    ProductSKU = lens.Product.ProductSKU,
                    ProductName = lens.Product.ProductName,
                    LensSPH = lens.LensSPH,
                    LensCYL = lens.LensCYL,
                    ProductRetailPrice = lens.Product.ProductRetailPrice,
                    ProductQuantity = lens.Product.ProductQuantity

                };

                _lensviewmodel.Add(_lens);
            }

            _viewmodel.listproductorderdetail=_detailResult;
            _viewmodel.listproductlenssearch = _lensviewmodel.ToPagedList(page,5);

            if (Request.IsAjaxRequest())
            {

                return PartialView("_AddLens", _viewmodel.listproductlenssearch);
            }

            ViewBag.CustomerId = id;

            return View(_viewmodel);
        }
Пример #2
0
        public ActionResult Create(CustomerOrderVM customerorder)
        {
            var _orer = new Order()
            {
                //OrderDate=customerorder.OrderDate,
                OrderTotalPrice = customerorder.OrderTotalPrice,
                OrderTotalQuantity = customerorder.OrderTotalQuantity,
                OrderDiscount = customerorder.OrderDiscount,
                OrderTotalSum = customerorder.OrderTotalSum,
                StoreId = customerorder.StoreId,
                EmployeeId = customerorder.EmployeeId,
                OrderTypeId = customerorder.OrderTypeId,
                CustomerId = customerorder.CustomerId

            };

            if (ModelState.IsValid)
            {
                db.Orders.Add(_orer);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            foreach (var modelErrors in ModelState)
            {
                string propertyName = modelErrors.Key;
            }

            ViewBag.EmployeeId = new SelectList(db.Employees, "EmployeeId", "EmployeeName", customerorder.EmployeeId);
            return View();
        }