Exemplo n.º 1
0
        public ActionResult Create()
        {
            var model = new OptionCategoryEditViewModel();

            // Add two empty options to get started
            model.Options.Add(new OptionEditViewModel());
            model.Options.Add(new OptionEditViewModel());

            return(View(model));
        }
Exemplo n.º 2
0
 public ActionResult Edit(OptionCategoryEditViewModel model)
 {
     if (ModelState.IsValid)
     {
         var optionCategory = optionCategoryService.AddOrUpdate(model);
         return(RedirectToAction("Index")
                .WithSuccess(string.Format("Option category \"{0}\" has been updated".TA(), optionCategory.Name)));
     }
     return(View(model));
 }
        public ActionResult Create()
        {
            var model = new OptionCategoryEditViewModel();

            // Add two empty options to get started
            model.Options.Add(new OptionEditViewModel());
            model.Options.Add(new OptionEditViewModel());

            return View(model);
        }
Exemplo n.º 4
0
        public ActionResult Create([Bind(Exclude = "Id")] OptionCategoryEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                optionCategoryService.AddOrUpdate(model);

                var action = RedirectToAction("Index");

                if (settingService.Get <bool>(SettingField.ShowOptionTutorial))
                {
                    settingService.Set(SettingField.ShowOptionTutorial, false);
                    action = RedirectToAction("Welcome", "Home");
                }

                return(action.WithSuccess(string.Format("Option category \"{0}\" has been added".TA(), model.Name)));
            }

            return(View(model));
        }
Exemplo n.º 5
0
        public OptionCategory AddOrUpdate(OptionCategoryEditViewModel model)
        {
            OptionCategory optionCategory;
            if (model.Id == 0)
            {
                optionCategory = Mapper.Map<OptionCategory>(model);
                db.OptionCategories.Add(optionCategory);
            }
            else
            {
                optionCategory = Find(model.Id);
                Mapper.Map(model, optionCategory);

                if (model.Options != null)
                {
                    var options = optionService.FindByCategory(optionCategory.Id).ToList();
                    foreach (var option in options)
                    {
                        if (model.Options.None(o => o.Id == option.Id))
                        {
                            optionService.Delete(option.Id);
                        }
                    }
                }
            }

            db.SaveChanges();

            if (model.Options != null)
            {
                foreach (var optionModel in model.Options)
                {
                    optionModel.OptionCategoryId = optionCategory.Id;
                    optionService.AddOrUpdate(optionModel);
                }
            }

            return optionCategory;
        }
Exemplo n.º 6
0
        public OptionCategory AddOrUpdate(OptionCategoryEditViewModel model)
        {
            OptionCategory optionCategory;
            if (model.Id == 0)
            {
                optionCategory = Mapper.Map<OptionCategory>(model);
                db.OptionCategories.Add(optionCategory);
            }
            else
            {
                optionCategory = Find(model.Id);
                Mapper.Map(model, optionCategory);

                if (model.Options != null)
                {
                    var options = optionService.FindByCategory(optionCategory.Id).ToList();
                    foreach (var option in options)
                    {
                        if (model.Options.None(o => o.Id == option.Id))
                        {
                            optionService.Delete(option.Id);
                        }
                    }
                }
            }

            db.SaveChanges();

            if (model.Options != null)
            {
                foreach (var optionModel in model.Options)
                {
                    optionModel.OptionCategoryId = optionCategory.Id;
                    optionService.AddOrUpdate(optionModel);
                }
            }

            return optionCategory;
        }
 public ActionResult Edit(OptionCategoryEditViewModel model)
 {
     if (ModelState.IsValid)
     {
         var optionCategory = optionCategoryService.AddOrUpdate(model);
         return RedirectToAction("Index")
             .WithSuccess(string.Format("Option category \"{0}\" has been updated".TA(), optionCategory.Name));
     }
     return View(model);
 }