public ActionResult Product(ProductVm model)
        {
            if (ModelState.IsValid)
            {
                Entity.EntityModels.Product product = Mapper.Map <Entity.EntityModels.Product>(model);
                if (product.Id == 0)
                {
                    var extension = Path.GetExtension(model.Image1.FileName);

                    var path = Path.Combine(Server.MapPath("~/Content/Student/Photo/"));

                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }

                    model.Image1.SaveAs(path + model.Id + extension);

                    ViewBag.message = productManager.Save(product);
                }
                else
                {
                    ViewBag.message = productManager.Update(product);
                }
                model = new ProductVm();
                ModelState.Clear();
            }
            ViewBag.Items    = GetItemDropdownList();
            ViewBag.Brand    = GetItemForBrandDropdownList();
            ViewBag.Category = GetItemForCategoryDropdownList();
            List <Product> products = productManager.GetAllProduct();

            ViewBag.Product = products;
            return(View(model));
        }
Beispiel #2
0
        public ActionResult Product(ProductVm model)
        {
            if (ModelState.IsValid)
            {
                Entity.EntityModels.Product product = Mapper.Map <Entity.EntityModels.Product>(model);
                if (product.Id == 0)
                {
                    ViewBag.message = productManager.Save(product);
                }
                else
                {
                    ViewBag.message = productManager.Update(product);
                }
                model = new ProductVm();
                ModelState.Clear();
            }
            ViewBag.MaterialType = GetItemForMaterailTypeDropdownList();
            ViewBag.Brand        = GetItemForBrandDropdownList();
            ViewBag.Category     = GetItemForCategoryDropdownList();
            List <Product> products = productManager.GetAllProduct();

            ViewBag.Product = products;
            return(View(model));
        }