コード例 #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);
        }
コード例 #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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
ファイル: ManageCategoryController.cs プロジェクト: bivvo/RFH
        private ManageCategoryEditViewModel GetManageCategoryViewModel(Category category)
        {
            var model = new ManageCategoryEditViewModel
                            {
                                Category = category,
                                SuperCategories = GetSuperCategoryListItems(_dataContext.SuperCategories.ToList())
                            };

            return model;
        }