Пример #1
0
        public ActionResult AddCategory(CategoryViewModel model)
        {
            if (SiteConfiguration.IsDemoMode)
            {
                DisplayMessage("You can't save changes in demo mode.", MessageType.Warning);
                return RedirectToAction("AddCategory");
            }

            if (ModelState.IsValid)
            {
                var category = Mapper.Map<Category>(model);
                var result = adminService.AddCategory(category);

                if (result.Success)
                {
                    DisplayMessage(Translations.Validations.ItemAdded, MessageType.OK);
                    return RedirectToAction("Categories");
                }
                else
                    AddError(Translations.Validations.ErrorTryLater);
            }

            TempData["ModelState"] = ModelState;
            return RedirectToAction("AddCategory");
        }
Пример #2
0
        public ActionResult EditCategory(CategoryViewModel model, int id)
        {
            if (SiteConfiguration.IsDemoMode)
            {
                DisplayMessage("You can't save changes in demo mode.", MessageType.Warning);
                return RedirectToAction("EditCategory", new { id = id });
            }

            if (ModelState.IsValid)
            {
                var category = Mapper.Map<Category>(model);
                category.UpdatedByUserID = CurrentUser.Id;
                    
                var result = adminService.UpdateCategory(category);
                if (result.Success)
                    DisplayMessage(Translations.Validations.ItemUpdated, MessageType.Information);
                else
                    DisplayMessage(Translations.Validations.ErrorTryLater, MessageType.Error);
            }

            return RedirectToAction("EditCategory", new { id = id });
        }
Пример #3
0
        public ActionResult AddCategory()
        {
            var model = new CategoryViewModel();
            model.CategoryCount = adminService.GetCategoryCount();
            model.AvailableLanguages = adminService.GetAvailableLanguages();
            model.SortOrder = model.CategoryCount;

            return View(model);
        }