コード例 #1
0
        public ActionResult Create()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalogues))
            {
                return(AccessDeniedView());
            }

            var model = new CataloguesModel();

            //locales
            AddLocales(_languageService, model.Locales);

            //catalogues
            PrepareAllCataloguesModel(model);

            //ACL
            PrepareAclModel(model, null, false);

            //default values
            model.PageSize         = 4;
            model.Published        = true;
            model.IncludeInTopMenu = true;
            model.AllowCustomersToSelectPageSize = true;
            model.PageSizeOptions = _cataloguesSettings.DefaultCataloguesPageSizeOptions;

            return(View(model));
        }
コード例 #2
0
        protected virtual void SaveCataloguesAcl(Catalogues catalogues, CataloguesModel model)
        {
            var existingAclRecords = _aclService.GetAclRecords(catalogues);
            var allCustomerRoles   = _customerService.GetAllCustomerRoles(true);

            foreach (var customerRole in allCustomerRoles)
            {
                if (model.SelectedCustomerRoleIds != null && model.SelectedCustomerRoleIds.Contains(customerRole.Id))
                {
                    //new role
                    if (existingAclRecords.Count(acl => acl.CustomerRoleId == customerRole.Id) == 0)
                    {
                        _aclService.InsertAclRecord(catalogues, customerRole.Id);
                    }
                }
                else
                {
                    //remove role
                    var aclRecordToDelete = existingAclRecords.FirstOrDefault(acl => acl.CustomerRoleId == customerRole.Id);
                    if (aclRecordToDelete != null)
                    {
                        _aclService.DeleteAclRecord(aclRecordToDelete);
                    }
                }
            }
        }
コード例 #3
0
        protected virtual void UpdateLocales(Catalogues catalogues, CataloguesModel model)
        {
            foreach (var localized in model.Locales)
            {
                _localizedEntityService.SaveLocalizedValue(catalogues,
                                                           x => x.Name,
                                                           localized.Name,
                                                           localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(catalogues,
                                                           x => x.Description,
                                                           localized.Description,
                                                           localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(catalogues,
                                                           x => x.MetaKeywords,
                                                           localized.MetaKeywords,
                                                           localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(catalogues,
                                                           x => x.MetaDescription,
                                                           localized.MetaDescription,
                                                           localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(catalogues,
                                                           x => x.MetaTitle,
                                                           localized.MetaTitle,
                                                           localized.LanguageId);

                //search engine name
                var seName = catalogues.ValidateSeName(localized.SeName, localized.Name, false);
                _urlRecordService.SaveSlug(catalogues, seName, localized.LanguageId);
            }
        }
コード例 #4
0
        protected virtual void PrepareAclModel(CataloguesModel model, Catalogues catalogues, bool excludeProperties)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            model.AvailableCustomerRoles = _customerService
                                           .GetAllCustomerRoles(true)
                                           .Select(cr => cr.ToModel())
                                           .ToList();
            if (!excludeProperties)
            {
                if (catalogues != null)
                {
                    model.SelectedCustomerRoleIds = _aclService.GetCustomerRoleIdsWithAccess(catalogues);
                }
            }
        }
コード例 #5
0
        public ActionResult Create(CataloguesModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalogues))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var catalogues = model.ToEntity();
                catalogues.CreatedOnUtc = DateTime.UtcNow;
                catalogues.UpdatedOnUtc = DateTime.UtcNow;
                _cataloguesService.InsertCatalogues(catalogues);
                //search engine name
                model.SeName = catalogues.ValidateSeName(model.SeName, catalogues.Name, true);
                _urlRecordService.SaveSlug(catalogues, model.SeName, 0);
                //locales
                UpdateLocales(catalogues, model);

                //update picture seo file name
                UpdatePictureSeoNames(catalogues);
                //ACL (customer roles)
                SaveCataloguesAcl(catalogues, model);


                //activity log
                _customerActivityService.InsertActivity("AddNewCatalogues", _localizationService.GetResource("ActivityLog.AddNewCatalogues"), catalogues.Name);

                SuccessNotification(_localizationService.GetResource("Admin.News.Catalogues.Added"));
                return(continueEditing ? RedirectToAction("Edit", new { id = catalogues.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form

            //catalogues
            PrepareAllCataloguesModel(model);

            //ACL
            PrepareAclModel(model, null, true);

            return(View(model));
        }
コード例 #6
0
        protected virtual void PrepareAllCataloguesModel(CataloguesModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            model.AvailableCatalogues.Add(new SelectListItem
            {
                Text  = "[None]",
                Value = "0"
            });
            var catalogues = _cataloguesService.GetAllCatalogues(showHidden: true);

            foreach (var c in catalogues)
            {
                model.AvailableCatalogues.Add(new SelectListItem
                {
                    Text  = c.GetFormattedBreadCrumb(catalogues),
                    Value = c.Id.ToString()
                });
            }
        }
コード例 #7
0
        protected virtual void PrepareAclModel(CataloguesModel model, Catalogues catalogues, bool excludeProperties)
        {
            if (model == null)
                throw new ArgumentNullException("model");

            model.AvailableCustomerRoles = _customerService
                .GetAllCustomerRoles(true)
                .Select(cr => cr.ToModel())
                .ToList();
            if (!excludeProperties)
            {
                if (catalogues != null)
                {
                    model.SelectedCustomerRoleIds = _aclService.GetCustomerRoleIdsWithAccess(catalogues);
                }
            }
        }
コード例 #8
0
        public ActionResult NewsUpdate(CataloguesModel.CataloguesNewsModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalogues))
                return AccessDeniedView();

            var newsCatalogues = _cataloguesService.GetNewsCataloguesById(model.Id);
            if (newsCatalogues == null)
                throw new ArgumentException("No news catalogues mapping found with the specified id");

            newsCatalogues.IsFeaturedNews = model.IsFeaturedNews;
            newsCatalogues.DisplayOrder = model.DisplayOrder;
            _cataloguesService.UpdateNewsCatalogues(newsCatalogues);

            return new NullJsonResult();
        }
コード例 #9
0
        public ActionResult NewsAddPopupList(DataSourceRequest command, CataloguesModel.AddCataloguesNewsModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalogues))
                return AccessDeniedView();

            var gridModel = new DataSourceResult();
            var news = _newsService.SearchNews(
                keywords: model.SearchNewsTitle,
                pageIndex: command.Page - 1,
                pageSize: command.PageSize,
                showHidden: true
                );
            gridModel.Data = news.Select(x => x.ToModel());
            gridModel.Total = news.TotalCount;

            return Json(gridModel);
        }
コード例 #10
0
        public ActionResult NewsAddPopup(string btnId, string formId, CataloguesModel.AddCataloguesNewsModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalogues))
                return AccessDeniedView();

            if (model.SelectedNewsIds != null)
            {
                foreach (int id in model.SelectedNewsIds)
                {
                    var news = _newsService.GetNewsById(id);
                    if (news != null)
                    {
                        var existingNewsCatalogues = _cataloguesService.GetNewsCataloguesByCatalogueId(model.CatalogueId, 0, int.MaxValue, true);
                        if (existingNewsCatalogues.FindNewsCatalogues(id, model.CatalogueId) == null)
                        {
                            _cataloguesService.InsertNewsCatalogues(
                                new NewsCatalogues
                                {
                                    CatalogueId = model.CatalogueId,
                                    NewsId = id,
                                    IsFeaturedNews = false,
                                    DisplayOrder = 1
                                });
                        }
                    }
                }
            }

            ViewBag.RefreshPage = true;
            ViewBag.btnId = btnId;
            ViewBag.formId = formId;
            return View(model);
        }
コード例 #11
0
        public ActionResult Edit(CataloguesModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalogues))
                return AccessDeniedView();

            var catalogues = _cataloguesService.GetCatalogueById(model.Id);
            if (catalogues == null || catalogues.Deleted)
                //No catalogues found with the specified id
                return RedirectToAction("List");

            if (ModelState.IsValid)
            {
                int prevPictureId = catalogues.PictureId;
                catalogues = model.ToEntity(catalogues);
                catalogues.UpdatedOnUtc = DateTime.UtcNow;
                _cataloguesService.UpdateCatalogues(catalogues);
                //search engine name
                model.SeName = catalogues.ValidateSeName(model.SeName, catalogues.Name, true);
                _urlRecordService.SaveSlug(catalogues, model.SeName, 0);
                //locales
                UpdateLocales(catalogues, model);

                _cataloguesService.UpdateCatalogues(catalogues);

                //delete an old picture (if deleted or updated)
                if (prevPictureId > 0 && prevPictureId != catalogues.PictureId)
                {
                    var prevPicture = _pictureService.GetPictureById(prevPictureId);
                    if (prevPicture != null)
                        _pictureService.DeletePicture(prevPicture);
                }
                //update picture seo file name
                UpdatePictureSeoNames(catalogues);
                //ACL
                SaveCataloguesAcl(catalogues, model);

                //activity log
                _customerActivityService.InsertActivity("EditCatalogues", _localizationService.GetResource("ActivityLog.EditCatalogues"), catalogues.Name);

                SuccessNotification(_localizationService.GetResource("Admin.News.Catalogues.Updated"));
                if (continueEditing)
                {
                    //selected tab
                    SaveSelectedTabIndex();

                    return RedirectToAction("Edit", catalogues.Id);
                }
                return RedirectToAction("List");
            }

            //If we got this far, something failed, redisplay form

            //catalogues
            PrepareAllCataloguesModel(model);
            //ACL
            PrepareAclModel(model, catalogues, true);

            return View(model);
        }
コード例 #12
0
 public static Catalogues ToEntity(this CataloguesModel model, Catalogues destination)
 {
     return(model.MapTo(destination));
 }
コード例 #13
0
        protected virtual void UpdateLocales(Catalogues catalogues, CataloguesModel model)
        {
            foreach (var localized in model.Locales)
            {
                _localizedEntityService.SaveLocalizedValue(catalogues,
                                                               x => x.Name,
                                                               localized.Name,
                                                               localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(catalogues,
                                                           x => x.Description,
                                                           localized.Description,
                                                           localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(catalogues,
                                                           x => x.MetaKeywords,
                                                           localized.MetaKeywords,
                                                           localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(catalogues,
                                                           x => x.MetaDescription,
                                                           localized.MetaDescription,
                                                           localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(catalogues,
                                                           x => x.MetaTitle,
                                                           localized.MetaTitle,
                                                           localized.LanguageId);

                //search engine name
                var seName = catalogues.ValidateSeName(localized.SeName, localized.Name, false);
                _urlRecordService.SaveSlug(catalogues, seName, localized.LanguageId);
            }
        }
コード例 #14
0
        public ActionResult Edit(CataloguesModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalogues))
            {
                return(AccessDeniedView());
            }

            var catalogues = _cataloguesService.GetCatalogueById(model.Id);

            if (catalogues == null || catalogues.Deleted)
            {
                //No catalogues found with the specified id
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                int prevPictureId = catalogues.PictureId;
                catalogues = model.ToEntity(catalogues);
                catalogues.UpdatedOnUtc = DateTime.UtcNow;
                _cataloguesService.UpdateCatalogues(catalogues);
                //search engine name
                model.SeName = catalogues.ValidateSeName(model.SeName, catalogues.Name, true);
                _urlRecordService.SaveSlug(catalogues, model.SeName, 0);
                //locales
                UpdateLocales(catalogues, model);

                _cataloguesService.UpdateCatalogues(catalogues);

                //delete an old picture (if deleted or updated)
                if (prevPictureId > 0 && prevPictureId != catalogues.PictureId)
                {
                    var prevPicture = _pictureService.GetPictureById(prevPictureId);
                    if (prevPicture != null)
                    {
                        _pictureService.DeletePicture(prevPicture);
                    }
                }
                //update picture seo file name
                UpdatePictureSeoNames(catalogues);
                //ACL
                SaveCataloguesAcl(catalogues, model);

                //activity log
                _customerActivityService.InsertActivity("EditCatalogues", _localizationService.GetResource("ActivityLog.EditCatalogues"), catalogues.Name);

                SuccessNotification(_localizationService.GetResource("Admin.News.Catalogues.Updated"));
                if (continueEditing)
                {
                    //selected tab
                    SaveSelectedTabIndex();

                    return(RedirectToAction("Edit", catalogues.Id));
                }
                return(RedirectToAction("List"));
            }


            //If we got this far, something failed, redisplay form

            //catalogues
            PrepareAllCataloguesModel(model);
            //ACL
            PrepareAclModel(model, catalogues, true);

            return(View(model));
        }
コード例 #15
0
        protected virtual void PrepareAllCataloguesModel(CataloguesModel model)
        {
            if (model == null)
                throw new ArgumentNullException("model");

            model.AvailableCatalogues.Add(new SelectListItem
            {
                Text = "[None]",
                Value = "0"
            });
            var catalogues = _cataloguesService.GetAllCatalogues(showHidden: true);
            foreach (var c in catalogues)
            {
                model.AvailableCatalogues.Add(new SelectListItem
                {
                    Text = c.GetFormattedBreadCrumb(catalogues),
                    Value = c.Id.ToString()
                });
            }
        }
コード例 #16
0
 protected virtual void SaveCataloguesAcl(Catalogues catalogues, CataloguesModel model)
 {
     var existingAclRecords = _aclService.GetAclRecords(catalogues);
     var allCustomerRoles = _customerService.GetAllCustomerRoles(true);
     foreach (var customerRole in allCustomerRoles)
     {
         if (model.SelectedCustomerRoleIds != null && model.SelectedCustomerRoleIds.Contains(customerRole.Id))
         {
             //new role
             if (existingAclRecords.Count(acl => acl.CustomerRoleId == customerRole.Id) == 0)
                 _aclService.InsertAclRecord(catalogues, customerRole.Id);
         }
         else
         {
             //remove role
             var aclRecordToDelete = existingAclRecords.FirstOrDefault(acl => acl.CustomerRoleId == customerRole.Id);
             if (aclRecordToDelete != null)
                 _aclService.DeleteAclRecord(aclRecordToDelete);
         }
     }
 }
コード例 #17
0
        public ActionResult Create(CataloguesModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalogues))
                return AccessDeniedView();

            if (ModelState.IsValid)
            {
                var catalogues = model.ToEntity();
                catalogues.CreatedOnUtc = DateTime.UtcNow;
                catalogues.UpdatedOnUtc = DateTime.UtcNow;
                _cataloguesService.InsertCatalogues(catalogues);
                //search engine name
                model.SeName = catalogues.ValidateSeName(model.SeName, catalogues.Name, true);
                _urlRecordService.SaveSlug(catalogues, model.SeName, 0);
                //locales
                UpdateLocales(catalogues, model);

                //update picture seo file name
                UpdatePictureSeoNames(catalogues);
                //ACL (customer roles)
                SaveCataloguesAcl(catalogues, model);

                //activity log
                _customerActivityService.InsertActivity("AddNewCatalogues", _localizationService.GetResource("ActivityLog.AddNewCatalogues"), catalogues.Name);

                SuccessNotification(_localizationService.GetResource("Admin.News.Catalogues.Added"));
                return continueEditing ? RedirectToAction("Edit", new { id = catalogues.Id }) : RedirectToAction("List");
            }

            //If we got this far, something failed, redisplay form

            //catalogues
            PrepareAllCataloguesModel(model);

            //ACL
            PrepareAclModel(model, null, true);

            return View(model);
        }
コード例 #18
0
        public ActionResult Create()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalogues))
                return AccessDeniedView();

            var model = new CataloguesModel();
            //locales
            AddLocales(_languageService, model.Locales);

            //catalogues
            PrepareAllCataloguesModel(model);

            //ACL
            PrepareAclModel(model, null, false);

            //default values
            model.PageSize = 4;
            model.Published = true;
            model.IncludeInTopMenu = true;
            model.AllowCustomersToSelectPageSize = true;
            model.PageSizeOptions = _cataloguesSettings.DefaultCataloguesPageSizeOptions;

            return View(model);
        }
コード例 #19
0
 public static Catalogues ToEntity(this CataloguesModel model)
 {
     return(model.MapTo <CataloguesModel, Catalogues>());
 }