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 })); }