Exemplo n.º 1
0
        public ActionResult Create(Category model)
        {
            if (ModelState.IsValid)
            {
                model.UrlFriendlyName = Regex.Replace(model.Name, @"[^\w]+", "-", RegexOptions.IgnoreCase);
                _dataContext.Categories.Add(model);
                _dataContext.SaveChanges();

                return RedirectToAction("Detail", new { model.Id });
            }

            return View(model);
        }
Exemplo n.º 2
0
        public ActionResult Create(FormCollection form)
        {
            Category category = new Category();
            if (TryUpdateModel(category, "Category"))
            {
                category.UrlFriendlyName = Regex.Replace(category.Name, @"[^\w]+", "-", RegexOptions.IgnoreCase);
                _dataContext.Categories.Add(category);
                _dataContext.SaveChanges();

                return RedirectToAction("Detail", new { category.Id });
            }

            var viewModel = GetManageCategoryViewModel(category);
            return View(viewModel);
        }
        public ActionResult Create(SuperCategory superCategory)
        {
            if (ModelState.IsValid)
            {
                var defaultCategory = new Category
                                          {
                                              Name = "Default category under " + superCategory.Name,
                                              SuperCategory = superCategory,
                                              UrlFriendlyName = "default"+superCategory.UrlFriendlyName,
                                              Description = "Bacon ipsum dolor sit amet pig pancetta corned beef, strip steak tail spare ribs venison short ribs turkey pork t-bone."
                                          };
                _dataContext.SuperCategories.Add(superCategory);
                _dataContext.Categories.Add(defaultCategory);
                _dataContext.SaveChanges();

                return RedirectToAction("Detail", new { id = superCategory.SuperCategoryId });
            }

            return View(superCategory);
        }
Exemplo n.º 4
0
        private ManageCategoryEditViewModel GetManageCategoryViewModel(Category category)
        {
            var model = new ManageCategoryEditViewModel
                            {
                                Category = category,
                                SuperCategories = GetSuperCategoryListItems(_dataContext.SuperCategories.ToList())
                            };

            return model;
        }