private void InstallRolesAtAPage()
        {
            if (_webPageRoleRepo.Table.Any())
            {
                return;
            }

            _unitOfWork.Complete();
            var firstPage = _webPageRepo.Table.First();
            var roles     = _roleManager.Roles;

            List <WebPageRole> wrList = new List <WebPageRole>();

            foreach (var role in roles)
            {
                WebPageRole pr = new WebPageRole();
                pr.WebPage = firstPage;
                pr.Name    = role.Name;

                wrList.Add(pr);
            }
            _webPageRoleRepo.AddRange(wrList);

            _unitOfWork.Complete();
        }
Example #2
0
        //[ValidateAntiForgeryToken]
        public ActionResult Edit(WebPageModel model, IFormCollection form)
        {
            var page = _webPageService.GetById(model.Id);

            if (!ModelState.IsValid)
            {
                PrepareWebPageModel(page, model);
                //model.AvailableThemes = _themeService.GetThemes().Select(x => new SelectListItem { Text = x });
                return(View(model));
            }

            if (model.Roles != null)
            {
                foreach (var role in model.Roles)
                {
                    var found = page.Roles.FirstOrDefault(x => x.Name == role.Name);
                    if (found == null)
                    { // new
                        found           = new WebPageRole();
                        found.Name      = role.Name;
                        found.CreatedOn = DateTime.Now;
                        found.UpdatedOn = DateTime.Now;
                        page.Roles.Add(found);
                    }
                    found.PermissionLevel = role.PermissionLevel;
                }
            }

            page = model.ToEntity(page);

            //var webPageAttributes = ParseCustomWebPageAttributes(page, form);
            //_genericAttributeService.SaveAttribute(page, SystemWebPageAttributeNames.CustomWebPageAttributes, webPageAttributes);


            ////custom address attributes
            //var customAttributes = form.ParseCustomAddressAttributes(_customAttributeParser, _customAttributeService);
            //var customAttributeWarnings = _customAttributeParser.GetAttributeWarnings(customAttributes);
            //page.CustomAttributes = customAttributes;

            _webPageService.Update(page);

            _urlRecordService.SaveSlug(page, page.VirtualPath, 0);

            return(RedirectToAction("Edit", new { pageId = page.Id }));
        }