Ejemplo n.º 1
0
        private void RemoveFieldsFromModelStateDependOnSectionType(ModelStateDictionary modelState, int sectionId)
        {
            PageSectionType sectionType = _dynamicPageSectionRepository.GetPageSectionType(sectionId);

            if (sectionId > 0)
            {
                if (sectionType != null)
                {
                    if (sectionType.MediaType == "None")
                    {
                        modelState.Remove("Section.Url");
                        modelState.Remove("Section.Photo");
                        modelState.Remove("Section.EnImageAlt");
                        modelState.Remove("Section.ArImageAlt");
                    }

                    if (sectionType.MediaType == "Video")
                    {
                        modelState.Remove("Section.Photo");
                        modelState.Remove("Section.EnImageAlt");
                        modelState.Remove("Section.ArImageAlt");
                    }

                    if (sectionType.MediaType == "Image")
                    {
                        modelState.Remove("Section.Url");
                    }
                }
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="name"></param>
 /// <param name="sectionType"></param>
 /// <param name="xmlSource"></param>
 public PageSection(string name, PageSectionType sectionType, string xmlSource)
 {
     _name        = name;
     _sectionType = sectionType;
     if (sectionType == PageSectionType.FromXML)
     {
         if (!string.IsNullOrEmpty(xmlSource))
         {
             _xmlSource = xmlSource;
         }
     }
     else
     {
         _xmlSource = null;
     }
 }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create(PageSectionCreateViewModel sectionViewModel)
        {
            List <PageSectionType> sectionTypes;

            RemoveFieldsFromModelStateDependOnSectionType(ModelState, sectionViewModel.SectionTypeId ?? 0);

            sectionViewModel.Section.EnDescription.ValidateHtml("EnDescription", ModelState);
            sectionViewModel.Section.ArDescription.ValidateHtml("ArDescription", ModelState);
            PageSectionType sectionType = null;

            if (sectionViewModel.SectionTypeId != null)
            {
                sectionType = _dynamicPageSectionRepository.GetPageSectionType(sectionViewModel.SectionTypeId.Value);
                if (sectionType.MediaType == SectionMediaType.Image.ToString() && sectionViewModel.Section.Photo == null)
                {
                    ModelState.AddModelError(nameof(sectionViewModel.Section.Photo), "you should uplaod a photo.");
                    _toastNotification.AddWarningToastMessage("you should uplaod a photo.");
                }
            }


            if (ModelState.IsValid)
            {
                sectionViewModel = RemoveTagsFromDescription(sectionViewModel);

                PageSectionVersion pageSectionVersion = sectionViewModel.MapToPageSectionVersion();


                if (sectionType.MediaType == SectionMediaType.Image.ToString())
                {
                    pageSectionVersion.Url = _fileService.UploadImageUrlNew(sectionViewModel.Section.Photo);
                }
                var user = await _userManager.GetUserAsync(HttpContext.User);

                pageSectionVersion.CreatedById  = user.Id;
                pageSectionVersion.CreationDate = DateTime.Now;

                PageSectionVersion newDynamicPageSectionVersion = _dynamicPageSectionVersionRepository.Add(pageSectionVersion);
                if (newDynamicPageSectionVersion != null)
                {
                    _toastNotification.AddSuccessToastMessage(ToasrMessages.AddSuccess);
                    if (sectionViewModel.submit != null)
                    {
                        return(RedirectToAction("Index", "DynamicSectionCard", new { id = newDynamicPageSectionVersion.Id, pageRouteVersionId = newDynamicPageSectionVersion.PageRouteVersionId }));
                    }

                    _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Add, "Dynamic Page > " + ViewBag.DynamicPageName + " > Sections > Add ", pageSectionVersion.EnTitle);

                    return(RedirectToAction("Index", new { pageRouteVersionId = newDynamicPageSectionVersion.PageRouteVersionId }));
                }
                else
                {
                    _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Warning, "Dynamic Page > " + ViewBag.DynamicPageName + " > Sections > Warning in Add", pageSectionVersion.EnTitle);
                    _toastNotification.AddErrorToastMessage(ToasrMessages.warning);

                    sectionTypes     = _dynamicPageSectionRepository.GetPageSectionTypes();
                    sectionViewModel = new PageSectionCreateViewModel(sectionTypes);

                    return(View(sectionViewModel));
                }
            }
            sectionTypes = _dynamicPageSectionRepository.GetPageSectionTypes();
            var pageRouteVer = sectionViewModel.pageRouteVersionId;

            sectionViewModel = new PageSectionCreateViewModel(sectionTypes);
            sectionViewModel.pageRouteVersionId = pageRouteVer;

            return(View(sectionViewModel));
        }