Exemple #1
0
        private void Load(int?catId, int?typeId)
        {
            List <SelectListItem>   lstCategories = new List <SelectListItem>();
            IList <ContentCategory> categories    = contentCategoryRepository.GetAll();

            foreach (ContentCategory cc in categories)
            {
                SelectListItem item = new SelectListItem();
                item.Text  = cc.Name;
                item.Value = cc.Id.ToString();
                if (catId.HasValue && catId.Value == cc.Id)
                {
                    item.Selected = true;
                }
                lstCategories.Add(item);
            }

            Array typeValues = Enum.GetValues(typeof(ContentType));
            List <SelectListItem> lstContentTypes = new List <SelectListItem>();

            foreach (ContentType ct in typeValues)
            {
                SelectListItem contentType = new SelectListItem();
                contentType.Text  = ct.ToString();
                contentType.Value = ((int)ct).ToString();
                if (typeId.HasValue && typeId == (int)ct)
                {
                    contentType.Selected = true;
                }

                lstContentTypes.Add(contentType);
            }

            ViewData["contentTypes"]      = lstContentTypes;
            ViewData["contentCategories"] = lstCategories;
        }
        private void FillViewData(ContentView cv, Content c)
        {
            IList <ContentCategory> categories = contentCategoryRepository.GetAll();

            List <SelectListItem> lstPublishers = new List <SelectListItem>();

            string[] users = null;
            MembershipUserCollection membershipUsers = new MembershipUserCollection();

            if (RolePermissionService.IsAuthor())
            {
                users = Roles.GetUsersInRole("editor");
                foreach (string editorName in users)
                {
                    membershipUsers.Add(Membership.GetUser(editorName));
                }
            }

            if (RolePermissionService.IsEditor())
            {
                users = Roles.GetUsersInRole("author");
                foreach (string authorName in users)
                {
                    membershipUsers.Add(Membership.GetUser(authorName));
                }

                users = Roles.GetUsersInRole("publisher");
                foreach (string publisherName in users)
                {
                    membershipUsers.Add(Membership.GetUser(publisherName));
                }
            }

            if (RolePermissionService.IsPublisher())
            {
                users = Roles.GetUsersInRole("editor");
                foreach (string editorName in users)
                {
                    membershipUsers.Add(Membership.GetUser(editorName));
                }
            }

            foreach (MembershipUser mu in membershipUsers)
            {
                SelectListItem item = new SelectListItem();
                item.Text  = mu.UserName;
                item.Value = mu.ProviderUserKey.ToString();
                lstPublishers.Add(item);
            }

            Array typeValues = Enum.GetValues(typeof(ContentType));
            List <SelectListItem> lstContentTypes = new List <SelectListItem>();

            if (c == null && cv.Id != 0)
            {
                c = contentManagerService.Get(cv.Id);
            }

            ContentType type = ContentType.Blog;

            if (c != null)
            {
                type = c.Type;
            }

            SelectListItem itemType = new SelectListItem();

            itemType.Text  = type.ToString();
            itemType.Value = ((int)type).ToString();
            lstContentTypes.Add(itemType);

            IList <FashionFlavor> flavors = fashionFlavorRepository.GetAll();

            if (c == null && cv.Id != 0)
            {
                c = contentManagerService.Get(cv.Id);
            }

            if (c != null)
            {
                viewData.CanApprove = RolePermissionService.CanApprove(c);
                viewData.CanAssign  = RolePermissionService.CanAssignTo(c);
            }

            viewData.Content           = cv;
            viewData.Flavors           = flavors;
            viewData.Publishers        = lstPublishers;
            viewData.ContentTypes      = lstContentTypes;
            viewData.ContentCategories = categories;
        }