Ejemplo n.º 1
0
        public IActionResult Put(long id, [FromBody] ProductWidgetForm model)
        {
            if (ModelState.IsValid)
            {
                var widgetInstance = _widgetInstanceRepository.Query().FirstOrDefault(x => x.Id == id);
                widgetInstance.Name         = model.Name;
                widgetInstance.WidgetZoneId = model.WidgetZoneId;
                widgetInstance.PublishStart = model.PublishStart;
                widgetInstance.PublishEnd   = model.PublishEnd;
                widgetInstance.Data         = JsonConvert.SerializeObject(model.Setting);

                _widgetInstanceRepository.SaveChanges();
                return(Ok());
            }

            return(new BadRequestObjectResult(ModelState));
        }
Ejemplo n.º 2
0
        public IActionResult Get(long id)
        {
            var widgetInstance = _widgetInstanceRepository.Query().FirstOrDefault(x => x.Id == id);
            var model          = new ProductWidgetForm
            {
                Id           = widgetInstance.Id,
                Name         = widgetInstance.Name,
                WidgetZoneId = widgetInstance.WidgetZoneId,
                PublishStart = widgetInstance.PublishStart,
                PublishEnd   = widgetInstance.PublishEnd,
                Setting      = JsonConvert.DeserializeObject <ProductWidgetSetting>(widgetInstance.Data)
            };

            var enumMetaData = MetadataProvider.GetMetadataForType(typeof(ProductWidgetOrderBy));

            return(Json(model));
        }
Ejemplo n.º 3
0
        public IActionResult Post([FromBody] ProductWidgetForm model)
        {
            if (ModelState.IsValid)
            {
                var widgetInstance = new WidgetInstance
                {
                    Name         = model.Name,
                    WidgetId     = 3,
                    WidgetZoneId = model.WidgetZoneId,
                    PublishStart = model.PublishStart,
                    PublishEnd   = model.PublishEnd,
                    Data         = JsonConvert.SerializeObject(model.Setting)
                };

                _widgetInstanceRepository.Add(widgetInstance);
                _widgetInstanceRepository.SaveChanges();
                return(Ok());
            }
            return(new BadRequestObjectResult(ModelState));
        }
        public IActionResult Post([FromBody] ProductWidgetForm model)
        {
            if (ModelState.IsValid)
            {
                var widgetInstance = new WidgetInstance
                {
                    Name         = model.Name,
                    WidgetId     = 3,
                    WidgetZoneId = model.WidgetZoneId,
                    PublishStart = model.PublishStart,
                    PublishEnd   = model.PublishEnd,
                    DisplayOrder = model.DisplayOrder,
                    Data         = JsonConvert.SerializeObject(model.Setting)
                };

                _widgetInstanceRepository.Add(widgetInstance);
                _widgetInstanceRepository.SaveChanges();
                return(CreatedAtAction(nameof(Get), new { id = widgetInstance.Id }, null));
            }

            return(BadRequest(ModelState));
        }