コード例 #1
0
        public ActionResult Create()
        {
            Uri previousPage = Request.UrlReferrer;

            var model = new CultureViewModel
            {
                PreviousUrl = (!previousPage.LocalPath.Contains("Culture")) ? previousPage : null
            };
            bool isDefaultExist = _cultureService.GetAll().Any(c => c.Default);
            model.IsAnyAlreayDefault = isDefaultExist;
            return View(model);
        }
コード例 #2
0
        public ActionResult Create(CultureViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (_cultureService.GetCultureByName(model.Name) == null)
                {
                    var culture = new BOCulture();
                    bool isDefaultExist = _cultureService.GetAll().Any(c => c.Default);

                    Mapper.Map<CultureViewModel, BOCulture>(model, culture);

                    try
                    {
                        var info = new CultureInfo(model.Name);
                        culture.DisplayName = info.DisplayName;
                        culture.EnglishName = info.EnglishName;
                        culture.Available = true;
                        culture.Default = !isDefaultExist;
                    }
                    catch (CultureNotFoundException)
                    {
                        ModelState.AddModelError("Message", "Culture code is not valid.");
                        return View(model);
                    }

                    _cultureService.Save(culture);

                    if (model.PreviousUrl != null)
                        return Redirect(model.PreviousUrl.AbsoluteUri);

                    return RedirectToAction("Index");
                }

                ModelState.AddModelError("Message", "Culture with this name already exists.");
            }

            return View(model);
        }
コード例 #3
0
        public ActionResult Edit(CultureViewModel model)
        {
            if (ModelState.IsValid)
            {
                BOCulture culture = _cultureService.GetCultureById(model.ID);
                Mapper.Map<CultureViewModel, BOCulture>(model, culture);

                _cultureService.Save(culture);

                return RedirectToAction("Index");
            }

            return View(model);
        }