Esempio n. 1
0
        public async Task <IActionResult> Edit(int Id)
        {
            var CurrentUser = await _userManager.GetUserAsync(User);

            var DefaultLanguageID = CurrentUser.DefaultLanguageId;

            var UICustomizationArray = new UICustomization(_context);

            ViewBag.Terms = await UICustomizationArray.UIArray(this.ControllerContext.RouteData.Values["controller"].ToString(), this.ControllerContext.RouteData.Values["action"].ToString(), DefaultLanguageID);

            Menus a = new Menus(_context);


            SqlParameter[] parameters =
            {
                new SqlParameter("@LanguageId", CurrentUser.DefaultLanguageId)
                ,                               new SqlParameter("@Id", Id)
            };

            var PageSectionEditGet = _context.ZdbPageSectionEditGet.FromSql("PageSectionEditGet @LanguageId, @Id", parameters).First();


            var PageSection = (from c in _pageSection.GetAllPageSections()
                               join l in _pageSectionLanguage.GetAllPageSectionLanguages()
                               on c.Id equals l.PageSectionId
                               where c.Id == Id && l.LanguageId == CurrentUser.DefaultLanguageId
                               orderby c.Sequence
                               select new SuObjectVMPageSection
            {
                Id = c.PageId
                ,
                ObjectId = c.Id
                ,
                LanguageId = l.LanguageId
                ,
                ObjectLanguageId = l.Id
                ,
                Type = c.PageSectionTypeId
                ,
                ShowSectionTitle = c.ShowSectionTitleName
                ,
                ShowSectionDescription = c.ShowSectionTitleDescription
                ,
                ShowContentTypeTitle = c.ShowContentTypeTitle
                ,
                ShowContentTypeTitleDescription = c.ShowContentTypeDescription
                ,
                OneTwoColumns = c.OneTwoColumns
                ,
                ContentTypeId = c.ContentTypeId
                ,
                SortById = c.SortById
                ,
                MaxContent = c.MaxContent
                ,
                HasPaging = c.HasPaging
                ,
                Sequence = c.Sequence
                ,
                Name = l.Name
                ,
                Description = l.Description
                ,
                Title = l.TitleName
                ,
                TitleDescription = l.TitleDescription
                ,
                MouseOver = l.MouseOver
            }).First();

            //Existing levels
            List <SelectListItem> ExistingLevels = (from c in _pageSection.GetAllPageSections()
                                                    join l in _pageSectionLanguage.GetAllPageSectionLanguages()
                                                    on c.Id equals l.PageSectionId
                                                    where c.PageId == PageSection.Id &&
                                                    l.LanguageId == CurrentUser.DefaultLanguageId
                                                    orderby c.Sequence
                                                    select new SelectListItem
            {
                Value = c.Sequence.ToString()
                ,
                Text = l.Name
            }).ToList();
            var TestForNull = (from c in _pageSection.GetAllPageSections()
                               join l in _pageSectionLanguage.GetAllPageSectionLanguages()
                               on c.Id equals l.PageSectionId
                               where c.Id == Id &&
                               l.LanguageId == CurrentUser.DefaultLanguageId
                               select c.Sequence).ToList();

            int MaxLevelSequence;

            if (TestForNull.Count() == 0)
            {
                MaxLevelSequence = 1;
            }
            else
            {
                MaxLevelSequence = (from c in _pageSection.GetAllPageSections()
                                    join l in _pageSectionLanguage.GetAllPageSectionLanguages()
                                    on c.Id equals l.PageSectionId
                                    where c.Id == Id &&
                                    l.LanguageId == CurrentUser.DefaultLanguageId
                                    select c.Sequence).Max();

                MaxLevelSequence++;
            }


            ExistingLevels.Add(new SelectListItem {
                Text = "add at bottom", Value = MaxLevelSequence.ToString()
            });

            //Existing levels

            //PageSectionTypes
            var ToForm = (from o in _pageSectionType.GetAllPageSectionTypes()
                          join l in _pageSectionTypeLanguage.GetAllPageSectionTypeLanguages()
                          on o.Id equals l.PageSectionTypeId
                          where l.LanguageId == CurrentUser.DefaultLanguageId
                          select new SuObjectVM
            {
                Id = o.Id
                ,
                Name = l.Name
            }).ToList();

            var TypeList = new List <SelectListItem>();

            foreach (var TypeFromDb in ToForm)
            {
                TypeList.Add(new SelectListItem
                {
                    Text  = TypeFromDb.Name,
                    Value = TypeFromDb.Id.ToString()
                });
            }

            //PageSectionTypes

            //ContentType
            var ContentTypes = (from o in _contentType.GetAllContentTypes()
                                join l in _contentTypeLanguage.GetAllContentTypeLanguages()
                                on o.Id equals l.ContentTypeId
                                where l.LanguageId == CurrentUser.DefaultLanguageId
                                select new SuObjectVM
            {
                Id = o.Id
                ,
                Name = l.Name
            }).ToList();

            var ContentTypeList = new List <SelectListItem>
            {
                new SelectListItem {
                    Value = "0", Text = "No type"
                }
            };

            foreach (var TypeFromDb in ContentTypes)
            {
                ContentTypeList.Add(new SelectListItem
                {
                    Text  = TypeFromDb.Name,
                    Value = TypeFromDb.Id.ToString()
                });
            }

            //ContentType


            var ClassificationAndStatus = new PageSectionAndStatusViewModel {
                SuObject = PageSection, SomeKindINumSelectListItem = ExistingLevels, ProbablyTypeListItem = TypeList, ProbablyTypeListItem2 = ContentTypeList
            };

            return(View(ClassificationAndStatus));
        }