//
        // GET: /NorthwindSvr/Details/5

        public ActionResult DetailsProduct(int? id, AllProductsModel allProductsModel, SuppliersCategoriesModel model)
        {
            Product p = null;
            if (id != null) p = allProductsModel.ProductById(id.Value);
            else
            {
                p = allProductsModel.ProductById((int)TempData["id"]);
            }
            if (p.Supplier == null) p.Supplier = model.SupplierList.Where(s => s.SupplierID == p.SupplierID).DefaultIfEmpty(null).First();
            if (p.Category == null) p.Category = model.CategoryList.Where(c => c.CategoryID == p.CategoryID).DefaultIfEmpty(null).First();
            return View(p);
        }
예제 #2
0
        public object BindModel(ControllerContext controllerContext,
                                ModelBindingContext bindingContext)
        {
            // get the model from the session 
            AllProductsModel allProductsModel =
                (AllProductsModel)controllerContext.HttpContext.Session[sessionKey];

            if (allProductsModel == null)
            {
                allProductsModel = new AllProductsModel();
                controllerContext.HttpContext.Session[sessionKey] = allProductsModel;
            }
            return allProductsModel;
        }
 public ActionResult AllProducts(AllProductsModel allProductsModel)
 {
     try
     {
         Logger.Instance.Debug("reached AllProducts controller");
         allProductsModel.Products = NorthwindSvr.GetProducts();
         return View(allProductsModel.Products);
     }
     catch (FaultException<BusinessServiceException> e)
     {
         Log.Error("Web.NorthwindController.AllProducts(...) Error from Business service layer: " + e.Message);
         throw;
     }
     catch (FaultException ex)
     {
         Log.Error("Web.NorthwindController.AllProducts(...) Error from Business service layer: " + ex.Message);
         throw;
     }
     catch (Exception exx)
     {
         Log.Fatal("Web.NorthwindController.AllProducts(...) Error: " + exx.Message);
         throw;
     }
 }
 public ActionResult CreateProduct(Product p, AllProductsModel allProductsModel)
 {
     NorthwindSvr.InsertProduct(p, true);
     TempData["id"] = p.ProductID;
     allProductsModel.Products.Insert(allProductsModel.Products.Count, p);
     return RedirectToAction("DetailsProduct");
 }
        //
        // GET: /NorthwindSvr/Edit/5

        public ActionResult EditProduct(int id, AllProductsModel allProductsModel, SuppliersCategoriesModel suppliersCategoriesModel)
        {
            Product p = allProductsModel.ProductById(id);
            ViewBag.SuppliersCategoriesModel = suppliersCategoriesModel;
            return View(p);
        }