// // ==================================================================================================== // public override object Execute(CPBaseClass CP) { // // -- read instanceId, guid created uniquely for this instance of the addon on a page var result = string.Empty; AddonMockDataModel settings = null; try { // // -- this is a dev tool -- catch excerptions and display // -- edit tool is outside to let them edit content on exception var settingsGuid = DesignBlockController.getSettingsGuid(CP, "Addon Mock", ref result); if (string.IsNullOrEmpty(settingsGuid)) { return(result); } // // -- locate or create a data record for this guid settings = AddonMockDataModel.createOrAddSettings(CP, settingsGuid); if (settings == null) { throw new ApplicationException("Could not create the design block settings record."); } // // -- translate the Db model to a view model and mustache it into the layout var viewModel = AddonMockViewModel.create(CP, settings); if (viewModel == null) { throw new ApplicationException("Could not create design block view model."); } object dataObject = Newtonsoft.Json.JsonConvert.DeserializeObject(viewModel.jsonData); result = Nustache.Core.Render.StringToString(viewModel.layout, dataObject); } catch (ArgumentException ex) { // // -- argument error result = "<div class=\"ccError\">" + ex.Message + "</div>"; } catch (ApplicationException ex) { // // -- app error result = "<div class=\"ccError\">" + ex.Message + "</div>"; } catch (Exception ex) { // // -- tool, just return the exception result = "<div class=\"ccError\">" + ex.Message + "</div>"; } // // -- if editing enabled, add the link and wrapperwrapper if (settings == null) { return(result); } return(CP.Content.GetEditWrapper(result, AddonMockDataModel.tableMetadata.contentName, settings.id)); }
// // ==================================================================================================== /// <summary> /// Populate the view model from the entity model /// </summary> /// <param name="cp"></param> /// <param name="settings"></param> /// <returns></returns> public static SampleViewModel create(CPBaseClass cp, SampleModel settings) { try { // // -- base fields var result = create <SampleViewModel>(cp, settings); // // -- custom result.imageUrl = string.IsNullOrEmpty(settings.imageFilename) ? "" : (cp.Site.FilePath + settings.imageFilename).Replace(" ", "%20"); result.styleAspectRatio = DesignBlockController.getAspectRationStyle(settings.imageAspectRatioId); result.manageAspectRatio = !string.IsNullOrEmpty(result.styleAspectRatio); // bool isTopElement = string.IsNullOrWhiteSpace(result.imageUrl); result.headline = settings.headline; result.headlineTopPadClass = isTopElement & (!string.IsNullOrEmpty(result.headline)) ? "" : "pt-3"; // isTopElement = isTopElement & string.IsNullOrWhiteSpace(result.headline); result.embed = settings.embed; result.headlineTopPadClass = isTopElement ? "" : "pt-3"; // isTopElement = isTopElement & string.IsNullOrWhiteSpace(result.embed); result.description = settings.description; result.descriptionTopPadClass = isTopElement ? "" : "pt-3"; // isTopElement = isTopElement & string.IsNullOrWhiteSpace(result.description); result.buttonUrl = GenericController.verifyProtocol(settings.buttonUrl); result.buttonText = string.IsNullOrWhiteSpace(settings.buttonText) ? string.Empty : settings.buttonText; result.btnStyleSelector = settings.btnStyleSelector; if ((string.IsNullOrEmpty(result.buttonText) | string.IsNullOrEmpty(result.buttonUrl))) { result.buttonText = ""; result.buttonUrl = ""; } result.buttonTopPadClass = isTopElement ? "" : "pt-3"; // return(result); } catch (Exception ex) { cp.Site.ErrorReport(ex); return(null); } }
// // ==================================================================================================== // public override object Execute(CPBaseClass CP) { const string designBlockName = "Forum"; try { using (var ae = new ApplicationController(CP)) { // // -- read instanceId, guid created uniquely for this instance of the addon on a page var result = string.Empty; var settingsGuid = DesignBlockController.getSettingsGuid(CP, designBlockName, ref result); if ((string.IsNullOrEmpty(settingsGuid))) { return(result); } // // -- locate or create a data record for this guid var settings = ForumModel.createOrAddSettings(CP, settingsGuid); if ((settings == null)) { throw new ApplicationException("Could not create the design block settings record."); } // // -- process buttons ae.processButtonSubmit(CP, settings); // // -- translate the Db model to a view model and mustache it into the layout var viewModel = ForumViewModel.create(CP, settings, ae); if ((viewModel == null)) { throw new ApplicationException("Could not create design block view model."); } result = Nustache.Core.Render.StringToString(DesignBlockController.getLayoutByGuid(CP, guidForumLayout, "Forum Layout", Contensive.Addon.Forum.Properties.Resources.ForumLayout), viewModel); // // -- if editing enabled, add the link and wrapperwrapper return(CP.Content.GetEditWrapper(result, ForumModel.tableMetadata.contentName, settings.id)); } } catch (Exception ex) { CP.Site.ErrorReport(ex); return("<!-- " + designBlockName + ", Unexpected Exception -->"); } }
// // ==================================================================================================== /// <summary> /// Populate the view model from the entity model /// </summary> /// <param name="cp"></param> /// <param name="settings"></param> /// <returns></returns> public static ForumViewModel create(CPBaseClass cp, ForumModel settings, ApplicationController ae) { int hint = 10; try { // // -- base fields string avatar = (string.IsNullOrWhiteSpace(ae.user.thumbnailFilename) ? ae.user.imageFilename : ae.user.thumbnailFilename); var result = create <ForumViewModel>(cp, settings); result.forumId = settings.id; result.forumName = settings.name; result.headline = settings.headline; result.description = settings.description; result.recaptcha = settings.recaptcha; result.userAuthenticated = cp.User.IsAuthenticated; result.addCommentName = ae.user.name; result.addCommentEmail = ae.user.email; result.addCommentImageFilename = DesignBlockController.getAvatarLink(cp, ae, ae.user.thumbnailFilename, ae.user.imageFilename); result.addCommentCopy = ""; result.commentList = new List <ForumComment>(); using (var cs = cp.CSNew()) { hint = 20; if (cs.OpenSQL(Contensive.Addon.Forum.Properties.Resources.selectSql.Replace("{forumId}", settings.id.ToString()))) { //int lastCommentId = 0; ForumComment comment = new ForumComment(); ForumCommentReply reply = new ForumCommentReply(); do { hint = 30; int commentId = cs.GetInteger("commentId"); if (commentId != 0) { hint = 40; // // -- this row has a valid comment if (commentId != comment.commentId) { hint = 50; // // -- this row is a new comment string commentBody = cs.GetText("comment"); string cmName = cs.GetText("cmName"); string cmEmail = cs.GetText("cmEmail"); DateTime cDateAdded = cs.GetDate("cDateAdded"); DateTime rightNow = DateTime.Now; string cDateCaption = (rightNow.AddDays(7).CompareTo(cDateAdded) > 0) ? cDateAdded.ToString("dddd, d MMMM") : cDateAdded.ToString("d MMMM yyyy"); string commentByLine = cmName; commentByLine += ((!string.IsNullOrWhiteSpace(commentByLine) && !string.IsNullOrWhiteSpace(cDateCaption)) ? " • " : "") + cDateCaption; commentByLine += ((!string.IsNullOrWhiteSpace(commentByLine)) ? " • " : ""); comment = new ForumComment() { commentId = commentId, comment = string.IsNullOrWhiteSpace(commentBody) ? "(empty)" : commentBody, commentUserName = cmName, commentUserEmail = cmEmail, commentByLine = commentByLine, commentImageFilename = DesignBlockController.getAvatarLink(cp, ae, cs.GetText("cmthumbfilename"), cs.GetText("cmImageFilename")), replyList = new List <ForumCommentReply>() }; result.commentList.Add(comment); } hint = 60; int replyId = cs.GetInteger("replyId"); if (replyId != 0) { hint = 70; // // -- this row has a valid reply if (replyId != reply.replyId) { // // -- this row has a new reply DateTime rDateAdded = cs.GetDate("rDateAdded"); DateTime rightNow = DateTime.Now; string rDateCaption = (rightNow.AddDays(7).CompareTo(rDateAdded) > 0) ? rDateAdded.ToString("dddd, d MMMM") : rDateAdded.ToString("d MMMM yyyy"); string replyByLine = cs.GetText("rmName"); replyByLine += ((!string.IsNullOrWhiteSpace(replyByLine) && !string.IsNullOrWhiteSpace(rDateCaption)) ? " • " : "") + rDateCaption; reply = new ForumCommentReply() { replyId = cs.GetInteger("replyId"), reply = cs.GetText("reply"), replyUserName = cs.GetText("rmName"), replyUserEmail = cs.GetText("rmEmail"), replyByLine = replyByLine, replyImageFilename = DesignBlockController.getAvatarLink(cp, ae, cs.GetText("cmthumbfilename"), cs.GetText("rmImageFilename")) }; comment.replyList.Add(reply); } } } hint = 80; cs.GoNext(); } while (cs.OK()); } } // // -- now reverse the list for display hint = 90; foreach (var comment in result.commentList) { comment.replyList.Reverse(); } result.commentList.Reverse(); // // -- return the list return(result); } catch (Exception ex) { cp.Site.ErrorReport(ex, "hint-" + hint.ToString()); return(null); } }