Ejemplo n.º 1
0
        private SpaceBarWidgetForm ToSpaceBarWidgetFormModel(IFormCollection formCollection)
        {
            var model = new SpaceBarWidgetForm();

            model.Name         = formCollection["name"];
            model.WidgetZoneId = int.Parse(formCollection["widgetZoneId"]);
            int.TryParse(formCollection["displayOrder"], out int displayOrder);
            model.DisplayOrder = displayOrder;
            if (DateTimeOffset.TryParse(formCollection["publishStart"], out DateTimeOffset publishStart))
            {
                model.PublishStart = publishStart;
            }

            if (DateTimeOffset.TryParse(formCollection["publishEnd"], out DateTimeOffset publishEnd))
            {
                model.PublishEnd = publishEnd;
            }

            int numberOfItems = int.Parse(formCollection["numberOfItems"]);

            for (var i = 0; i < numberOfItems; i++)
            {
                var item = new SpaceBarWidgetSetting();
                item.Title       = formCollection[$"items[{i}][title]"];
                item.Description = formCollection[$"items[{i}][description]"];
                item.IconHtml    = formCollection[$"items[{i}][iconHtml]"];
                item.Image       = formCollection[$"items[{i}][image]"];
                item.UploadImage = formCollection.Files[$"items[{i}][uploadImage]"];
                model.Items.Add(item);
            }

            return(model);
        }
Ejemplo n.º 2
0
        public IActionResult Get(long id)
        {
            var widgetInstance = _widgetInstanceRepository.Query().FirstOrDefault(x => x.Id == id);
            var model          = new SpaceBarWidgetForm
            {
                Id           = widgetInstance.Id,
                Name         = widgetInstance.Name,
                WidgetZoneId = widgetInstance.WidgetZoneId,
                PublishStart = widgetInstance.PublishStart,
                PublishEnd   = widgetInstance.PublishEnd,
                DisplayOrder = widgetInstance.DisplayOrder,
                Items        = JsonConvert.DeserializeObject <IList <SpaceBarWidgetSetting> >(widgetInstance.Data)
            };

            foreach (var item in model.Items)
            {
                if (string.IsNullOrEmpty(item.Image))
                {
                    continue;
                }

                item.ImageUrl = _mediaService.GetMediaUrl(item.Image);
            }

            return(Json(model));
        }
        public IActionResult Get(long id)
        {
            var widgetInstance = _widgetInstanceRepository.Query().FirstOrDefault(x => x.Id == id);
            var model          = new SpaceBarWidgetForm
            {
                Id           = widgetInstance.Id,
                Name         = widgetInstance.Name,
                WidgetZoneId = widgetInstance.WidgetZoneId,
                PublishStart = widgetInstance.PublishStart,
                PublishEnd   = widgetInstance.PublishEnd,
                Items        = JsonConvert.DeserializeObject <IList <SpaceBarWidgetSetting> >(widgetInstance.Data)
            };

            return(Json(model));
        }