Example #1
0
        //Used for testing the new widgetized search page
        public ActionResult SearchWidget(int widgetID = 0)
        {
            var widget = WidgetServices.Get(widgetID) ?? new Widget();
            var vm     = JsonConvert.DeserializeObject <WidgetV2>(widget.CustomStyles ?? "{}", new JsonSerializerSettings()
            {
                Error = IgnoreDeserializationErrors
            });

            //vm.Created = widget.Created;
            //vm.LastUpdated = widget.LastUpdated;

            return(View("~/views/widget/searchwidget.cshtml", vm));
        }
Example #2
0
        //


        public JsonResult SaveWidgetV2()
        {
            //Manually bind large JSON document
            var model = Helpers.BindJsonModel <WidgetV2>(Request.InputStream, "data");

            //Convert
            var toSave = V2toV1(model);

            //Save the data
            var result   = new WidgetV2();
            var messages = new List <string>();

            if (!string.IsNullOrWhiteSpace(toSave.WidgetAlias))
            {
                var widgetExisting = WidgetServices.GetByAlias(toSave.WidgetAlias);
                if (widgetExisting != null && widgetExisting.Id > 0 && widgetExisting.Id != toSave.Id)
                {
                    messages.Add("Widget Alias already exist");
                    return(JsonResponse(null, false, "error", messages));
                }
            }

            if (!new WidgetServices().Save(toSave, ref messages))
            {
                LoggingHelper.DoTrace(5, "WidgetController.SaveWidgetV2. Errors on save: " + string.Join("\n\r>", messages));
                return(JsonResponse(null, false, "error", messages));
            }

            //Copy key properties from newly-saved widget (such as ID) to the V2 widget
            var saved = WidgetServices.Get(toSave.Id);

            result                 = JsonConvert.DeserializeObject <WidgetV2>(saved.CustomStyles);
            result.Created         = saved.Created;
            result.LastUpdated     = saved.LastUpdated;
            result.RowId           = saved.RowId;
            result.Id              = saved.Id;
            result.CreatedById     = saved.CreatedById;
            result.LastUpdatedById = saved.LastUpdatedById;
            //SimpleUpdate( saved, result );
            //result.UrlName = saved.WidgetAlias;

            //Save again to ensure the V2 data has the correct key properties
            saved.CustomStyles = JsonConvert.SerializeObject(result);
            new WidgetServices().Save(saved, ref messages);

            return(JsonResponse(result, true, "okay", null));
        }
Example #3
0
        public JsonResult GetWidget(int widgetId)
        {
            Widget widget = WidgetServices.Get(widgetId);

            if (!string.IsNullOrEmpty(widget.CustomStyles))
            {
                //this should be done in factory manager
                //widget.WidgetStyles = JsonConvert.DeserializeObject<WidgetStyles>( widget.CustomStyles );
            }
            else
            {
                widget.WidgetStyles = new WidgetStyles();
            }
            List <string> messages = new List <string>();

            if (widget == null)
            {
                messages.Add("Widget not found");
                return(JsonResponse(new Widget(), false, "", messages));
            }
            return(JsonResponse(widget, true, "success", null));
        }