public virtual ActionResult Save(SectionViewModel model)
        {
            if (ModelState.IsValid)
            {
                var section = sectionService.Find(model.Id);

                if (section == null || !permissionService.IsAllowed((Int32)SectionOperations.Manage, this.CorePrincipal(), typeof(Section), section.Id, IsSectionOwner(section), PermissionOperationLevel.Object))
                {
                    throw new HttpException((int)HttpStatusCode.NotFound, HttpContext.Translate("Messages.NotFound", ResourceHelper.GetControllerScope(this)));
                }

                if (sectionService.Save(model.MapTo(section)))
                {
                    //save locale
                    var           localeService = ServiceLocator.Current.GetInstance <ISectionLocaleService>();
                    SectionLocale locale        = localeService.GetLocale(section.Id, model.SelectedCulture);
                    locale = model.MapLocaleTo(locale ?? new SectionLocale {
                        Section = section
                    });

                    localeService.Save(locale);

                    Success(HttpContext.Translate("Messages.Success", String.Empty));
                    return(RedirectToAction(WebContentMVC.Section.Edit(model.Id)));
                }
            }
            else
            {
                Error(HttpContext.Translate("Messages.ValidationError", String.Empty));
            }

            model.AllowManage = true;

            return(View("Edit", model));
        }
        public virtual ActionResult ChangeLanguage(long sectionId, String culture)
        {
            var section = sectionService.Find(sectionId);

            if (section == null || !permissionService.IsAllowed((Int32)SectionOperations.View, this.CorePrincipal(), typeof(Section), section.Id, IsSectionOwner(section), PermissionOperationLevel.Object))
            {
                throw new HttpException((int)HttpStatusCode.NotFound, HttpContext.Translate("Messages.NotFound", ResourceHelper.GetControllerScope(this)));
            }

            bool allowManage = permissionService.IsAllowed((Int32)SectionOperations.Manage, this.CorePrincipal(),
                                                           typeof(Section), section.Id, IsSectionOwner(section),
                                                           PermissionOperationLevel.Object);

            SectionViewModel model = new SectionViewModel {
                AllowManage = allowManage
            }.MapFrom(section);

            model.SelectedCulture = culture;

            //get locale
            var           localeService = ServiceLocator.Current.GetInstance <ISectionLocaleService>();
            SectionLocale locale        = localeService.GetLocale(sectionId, culture);

            if (locale != null)
            {
                model.MapLocaleFrom(locale);
            }

            return(PartialView("SectionDetails", model));
        }
        public SectionViewModel MapLocaleFrom(SectionLocale locale)
        {
            Title           = locale.Title;
            Description     = locale.Description;
            SelectedCulture = locale.Culture;

            return(this);
        }
 public SectionLocale MapLocaleTo(SectionLocale locale)
 {
     locale.Title       = Title;
     locale.Description = Description;
     if (SelectedCulture != null)
     {
         locale.Culture = SelectedCulture;
     }
     return(locale);
 }