public virtual ActionResult Save(CategoryViewModel model)
        {
            if (ModelState.IsValid)
            {
                var category = categoryService.Find(model.Id);

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

                if (categoryService.Save(model.MapTo(category)))
                {
                    //save locale
                    var localeService = ServiceLocator.Current.GetInstance <ICategoryLocaleService>();
                    WebContentCategoryLocale locale = localeService.GetLocale(category.Id, model.SelectedCulture);
                    locale = model.MapLocaleTo(locale ?? new WebContentCategoryLocale {
                        Category = category
                    });

                    localeService.Save(locale);

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

            model.AllowManage = true;

            return(View("Edit", model));
        }
        public virtual ActionResult ChangeLanguage(long categoryId, String culture)
        {
            var category = categoryService.Find(categoryId);

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

            bool allowManage = permissionService.IsAllowed((Int32)CategoryOperations.Manage, this.CorePrincipal(),
                                                           typeof(WebContentCategory), category.Id, IsCategoryOwner(category),
                                                           PermissionOperationLevel.Object);

            CategoryViewModel model = new CategoryViewModel {
                AllowManage = allowManage
            }.MapFrom(category);

            model.SelectedCulture = culture;

            //get locale
            var localeService               = ServiceLocator.Current.GetInstance <ICategoryLocaleService>();
            WebContentCategoryLocale locale = localeService.GetLocale(categoryId, culture);

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

            return(PartialView("CategoryDetails", model));
        }
Beispiel #3
0
        public CategoryViewModel MapLocaleFrom(WebContentCategoryLocale locale)
        {
            Title           = locale.Title;
            Description     = locale.Description;
            SelectedCulture = locale.Culture;

            return(this);
        }
Beispiel #4
0
 public WebContentCategoryLocale MapLocaleTo(WebContentCategoryLocale locale)
 {
     locale.Title       = Title;
     locale.Description = Description;
     if (SelectedCulture != null)
     {
         locale.Culture = SelectedCulture;
     }
     return(locale);
 }