Exemplo n.º 1
0
        private string PostSlideForm(Form form, long tenantId, long pageId, long elementId)
        {
            // Get carousel slide details
            long          carouselSlideId = Convert.ToInt64(form.Data);
            string        uploadIds       = ((UploadField)form.Fields["upload"]).Value;
            string        pageValue       = ((SelectListField <string>)form.Fields["page"]).Value;
            CarouselSlide slide           = new CarouselSlide
            {
                TenantId        = tenantId,
                ElementId       = elementId,
                CarouselSlideId = carouselSlideId,
                Name            = ((TextField)form.Fields["name"]).Value,
                Description     = ((MultiLineTextField)form.Fields["description"]).Value,
                PageText        = ((TextField)form.Fields["pageText"]).Value,
                PageId          = pageValue == string.Empty ? null : (long?)Convert.ToInt64(pageValue),
                PageTenantId    = pageValue == string.Empty ? null : (long?)tenantId
            };

            if (!string.IsNullOrWhiteSpace(uploadIds))
            {
                string[] uploadParts = uploadIds.Split('|');
                slide.ImageTenantId          = tenantId;
                slide.ThumbnailImageUploadId = Convert.ToInt64(uploadParts[0]);
                slide.PreviewImageUploadId   = Convert.ToInt64(uploadParts[1]);
                slide.ImageUploadId          = Convert.ToInt64(uploadParts[2]);
            }

            // Validate supplied data
            _carouselValidator.ValidateSlide(slide);

            // Determine whether or not there are uncommitted slide images
            bool uncommittedSlideImages = true;

            if (carouselSlideId > 0)
            {
                ICarouselService carouselService = (ICarouselService)_elementFactory.GetElementService(FormId);
                CarouselSlide    currentSlide    = carouselService.ReadSlide(tenantId, elementId, carouselSlideId);
                uncommittedSlideImages = currentSlide.ImageUploadId != slide.ImageUploadId;
            }

            // Get slide view model and return it's JSON representation as form result status
            CarouselSlideViewModel slideViewModel = GetSlideViewModel(slide, uncommittedSlideImages);

            return(JsonConvert.SerializeObject(slideViewModel));
        }
Exemplo n.º 2
0
        /// <summary>
        /// TODO: Use proper URL routing here, do not hard wire these URLs.
        /// </summary>
        /// <param name="slide">Carousel slide.</param>
        /// <param name="uncommittedSlideImages">True if slide's image has changed and there are uncommitted image uploads, false if slide's image has not changed.</param>
        private CarouselSlideViewModel GetSlideViewModel(CarouselSlide slide, bool uncommittedSlideImages)
        {
            string imageUrl = null;

            if (uncommittedSlideImages)
            {
                imageUrl = string.Format("/uploads/{0}?t={0}", slide.ThumbnailImageUploadId);
            }
            else
            {
                imageUrl = string.Format("/elements/{0}/uploads/{1}?format=thumbnail&t={1}", slide.ElementId, slide.CarouselSlideId);
            }
            CarouselSlideViewModel slideViewModel = new CarouselSlideViewModel
            {
                CarouselSlideId        = slide.CarouselSlideId.ToString(),
                ThumbnailImageUploadId = slide.ThumbnailImageUploadId.ToString(),
                PreviewImageUploadId   = slide.PreviewImageUploadId.ToString(),
                ImageUploadId          = slide.ImageUploadId.ToString(),
                Name        = slide.Name,
                Description = slide.Description,
                PageId      = slide.PageId == null ? string.Empty : slide.PageId.ToString(),
                PageText    = slide.PageText,
                ImageUrl    = imageUrl
            };

            if (slide.PageId.HasValue)
            {
                if (string.IsNullOrWhiteSpace(slide.PageText))
                {
                    slideViewModel.ButtonText = _pageService.Read(slide.TenantId, slide.PageId.Value).Name;
                }
                else
                {
                    slideViewModel.ButtonText = slide.PageText;
                }
                slideViewModel.ButtonUrl = "/pages/" + slide.PageId.Value;
            }
            return(slideViewModel);
        }
Exemplo n.º 3
0
        private void PostSlidesForm(Form form, long pageId, long elementId)
        {
            // Get tenant ID
            long tenantId = _authenticationService.TenantId;

            // Get element service
            IAdvancedElementService elementService = (IAdvancedElementService)_elementFactory.GetElementService(FormId);

            // Get updated carousel settings
            CarouselSettings carouselSettings = (CarouselSettings)elementService.New(_authenticationService.TenantId);

            carouselSettings.ElementId = elementId;
            carouselSettings.Slides    = new List <CarouselSlide>();
            List <CarouselSlideViewModel> slideViewModels = JsonConvert.DeserializeObject <List <CarouselSlideViewModel> >(form.Data);

            for (int index = 0; index < slideViewModels.Count; index++)
            {
                CarouselSlideViewModel slideViewModel = slideViewModels[index];
                carouselSettings.Slides.Add(new CarouselSlide
                {
                    CarouselSlideId        = Convert.ToInt64(slideViewModel.CarouselSlideId),
                    Description            = slideViewModel.Description,
                    ElementId              = elementId,
                    ImageTenantId          = tenantId,
                    ImageUploadId          = Convert.ToInt64(slideViewModel.ImageUploadId),
                    Name                   = slideViewModel.Name,
                    PageId                 = string.IsNullOrWhiteSpace(slideViewModel.PageId) ? null : (long?)Convert.ToInt64(slideViewModel.PageId),
                    PageText               = string.IsNullOrWhiteSpace(slideViewModel.PageText) ? null : slideViewModel.PageText,
                    PageTenantId           = string.IsNullOrWhiteSpace(slideViewModel.PageId) ? null : (long?)tenantId,
                    PreviewImageUploadId   = Convert.ToInt64(slideViewModel.PreviewImageUploadId),
                    SortOrder              = index,
                    TenantId               = tenantId,
                    ThumbnailImageUploadId = Convert.ToInt64(slideViewModel.ThumbnailImageUploadId)
                });
            }

            // Perform the update
            elementService.Update(carouselSettings);
        }