public ActionResult ShowWidget( string widgetAlias )
        {
            if ( !string.IsNullOrWhiteSpace( widgetAlias ) )
            {
                var widget = WidgetServices.GetByAlias( widgetAlias );
                //if not found, display message somewhere - console message?
                if ( widget == null || widget.Id == 0 )
                {
                    workIT.Models.Common.SiteMessage msg = new workIT.Models.Common.SiteMessage() { Title = "Invalid Widget Request", Message = "ERROR - the requested Widget record was not found ", MessageType = "error" };
                    Session[ "SystemMessage" ] = msg;
                    return RedirectToAction( "Index", "Message" );
                }
                else
                {
                    string message = "";
                    //may already be in session, so remove and readd
                    //don't want this any longer
                    //if ( !WidgetServices.Activate( widget, message ) )
                    //{
                    //    workIT.Models.Common.SiteMessage msg = new workIT.Models.Common.SiteMessage() { Title = "Invalid Widget Request", Message = message, MessageType = "error" };
                    //    Session[ "SystemMessage" ] = msg;
                    //    return RedirectToAction( "Index", "Message" );
                    //}

                    var vm = Newtonsoft.Json.JsonConvert.DeserializeObject<workIT.Models.Common.WidgetV2>( widget.CustomStyles ?? "{}" );
                    return View( "~/views/widget/searchwidget.cshtml", vm );
                    //return View( "~/Views/Search/SearchV2.cshtml" );

                }
            }

            return RedirectToAction( "Index", "Home" );
        }
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 SaveWidget()
        {
            bool           isFileUploaded = false;
            List <string>  messages       = new List <string>();
            Widget         widgetData     = new Widget();
            WidgetServices widgetService  = new WidgetServices();

            string fileUploadStatus = "";
            var    w1 = Request.Params["widgetData"];

            if (w1 != null)
            {
                LoggingHelper.DoTrace(6, "WidgetController.SaveWidget. Entered.");

                widgetData = JsonConvert.DeserializeObject <Widget>(Request.Params["widgetData"]);
                if (!string.IsNullOrWhiteSpace(widgetData.WidgetAlias))
                {
                    var widgetExisting = WidgetServices.GetByAlias(widgetData.WidgetAlias);
                    if (widgetExisting != null && widgetExisting.Id > 0 && widgetExisting.Id != widgetData.Id)
                    {
                        messages.Add("Widget Alias already exist");
                        return(JsonResponse(widgetData, false, "failure", messages));
                    }
                }

                if (!widgetService.Save(widgetData, ref messages))
                {
                    LoggingHelper.DoTrace(5, "WidgetController.SaveWidget. Errors on save: " + string.Join("\n\r>", messages));
                    return(JsonResponse(widgetData, false, "", messages));
                }

                //don't call activate
                //WidgetServices.Activate( widgetData, string.Empty );

                //WHY the check for Files?
                //Need a check for actual entered data
                //skip for now
                if (string.IsNullOrEmpty(widgetData.WidgetStylesUrl) && Request.Files.Count == 0)
                {
                    //TODO - if no style changes, should delete any existing stylesheet
                    if (widgetData.WidgetStyles != null &&
                        widgetData.WidgetStyles.HasChanged())
                    {
                        //if ( this.ParseAndCreateUserStyleTemplate( widgetData, this.ControllerContext, Server.MapPath( "~/" ), "UserStyleTemplate", ref messages ) )
                        //    widgetService.Save( widgetData, ref messages );
                        //else
                        //{
                        //    //for now ignore errors?
                        //    return JsonResponse( widgetData, false, "failure", messages );
                        //}
                    }
                }
                //plan to chg this to get the text and pass as a string
                //if ( Request.Files.Count > 0 )
                //{
                //    LoggingHelper.DoTrace( 4, "WidgetController.SaveWidget. Have widget data and found files" );
                //    isFileUploaded = this.UploadStyle( Request.Files[ 0 ], widgetData );

                //    widgetService.Save( widgetData, ref messages );

                //    fileUploadStatus = isFileUploaded ? "Style template upload success" : fileUploadStatus;
                //    if ( !string.IsNullOrWhiteSpace( fileUploadStatus ) )
                //    {
                //        messages.Add( fileUploadStatus );
                //    }
                //}
            }
            else
            {
                //plan to chg this to get the text and pass as a string
                //if ( Request.Files.Count > 0 )
                //{
                //    LoggingHelper.DoTrace( 4, "WidgetController.SaveWidget. No widget data but found files" );
                //    isFileUploaded = this.UploadStyle( Request.Files[ 0 ], widgetData );

                //    widgetService.Save( widgetData, ref messages );

                //    fileUploadStatus = isFileUploaded ? "Style template upload success" : fileUploadStatus;
                //    if ( !string.IsNullOrWhiteSpace( fileUploadStatus ) )
                //    {
                //        messages.Add( fileUploadStatus );
                //    }
                //} else
                {
                    messages.Add("Error - no widget data was sent to the server.");
                    return(JsonResponse(widgetData, false, "failure", messages));
                }
            }

            LoggingHelper.DoTrace(6, "WidgetController.SaveWidget. Regular exit.");
            return(JsonResponse(widgetData, true, "success", new { isFileUploaded = isFileUploaded, fileUploadStatus = fileUploadStatus }));
        }