Esempio n. 1
0
        public ActionResult Create(FormCollection form, CreateEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var product = new Product();
                    product.Name        = model.Name;
                    product.Code        = model.Code;
                    product.Description = Server.HtmlDecode(model.Description);
                    product.UnitPrice   = model.UnitPrice;
                    product.IsActive    = model.IsActive;
                    product.IsFeatured  = model.IsFeatured;
                    product.Photo       = model.Photo;

                    var selectedTags       = form.GetValues("selectedTags");
                    var selectedAreas      = form.GetValues("selectedAreas");
                    var selectedCategories = form.GetValues("selectedCategories");
                    productProvider.AddOrUpdateProduct(product, selectedTags, selectedAreas, selectedCategories);
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(String.Empty, ex.Message);
                    Logger.ErrorException(ex.Message, ex);
                }
            }
            return(RedirectToAction("Create"));
        }