public async void ValidationIsTrueWithValidToken() { var options = new DbContextOptionsBuilder <ApiContext>() .UseInMemoryDatabase("CashlessRegistratorVT") .Options; var context = new ApiContext(options); var controller = new TokensController(context); var model = new Card { CardNumber = 4687334569974198, CVV = 233, CustomerId = 1 }; var response = await controller.GetToken(model); model = new Card { CVV = 233, CustomerId = 1, Token = 8419, CardId = 1 }; response = await controller.ValidateToken(model); Assert.IsType <AcceptedResult>(response.Result); }
public async void GetErrorSendingInvalidCard() { var options = new DbContextOptionsBuilder <ApiContext>() .UseInMemoryDatabase("CashlessRegistratorGT") .Options; var context = new ApiContext(options); var controller = new TokensController(context); var response = await controller.GetToken(null); Assert.IsType <BadRequestResult>(response.Result); }
public async Task GetToken_ItIsOkResult() { var provider = CreateServiceProvider(); var controller = new TokensController(provider.GetService <IQueryFactory>()); var mockOfGetCurrentUserStrategy = provider.GetService <Mock <IGetCurrentUserStrategy> >(); var userToReturn = new UserDto { Login = TestLogin, Roles = new[] { TestRole } }; mockOfGetCurrentUserStrategy.Setup(mock => mock.Get()).Returns(userToReturn); var result = await controller.GetAsync(); Assert.IsAssignableFrom <OkObjectResult>(result); }
public async Task GetToken_RoleFromTokenIsEqualFromCurrentUser() { var provider = CreateServiceProvider(); var controller = new TokensController(provider.GetService <IQueryFactory>()); var mockOfGetCurrentUserStrategy = provider.GetService <Mock <IGetCurrentUserStrategy> >(); var userToReturn = new UserDto { Login = TestLogin, Roles = new[] { TestRole } }; mockOfGetCurrentUserStrategy.Setup(mock => mock.Get()).Returns(userToReturn); var result = await controller.GetAsync(); var token = GetTokenFromResult(result); Assert.NotNull(token); Assert.Contains(token.Claims, claim => claim.Type == ClaimTypes.Role && claim.Value == userToReturn.Roles.Single()); }
public async void GetTokenSendingValidCard() { var options = new DbContextOptionsBuilder <ApiContext>() .UseInMemoryDatabase("CashlessRegistratorGT") .Options; var context = new ApiContext(options); var controller = new TokensController(context); var model = new Card { CardNumber = 4687334569974198, CVV = 233, CustomerId = 1 }; var response = await controller.GetToken(model); Assert.IsType <CreatedAtActionResult> (response.Result); }
public async void ValidationIsFalseWithInvalidToken() { var options = new DbContextOptionsBuilder <ApiContext>() .UseInMemoryDatabase("CashlessRegistratorVT") .Options; var context = new ApiContext(options); var controller = new TokensController(context); var model = new Card { CVV = 233, CustomerId = 1, Token = 8419, CardId = 1 }; var response = await controller.ValidateToken(model); Assert.IsType <UnauthorizedObjectResult>(response.Result); }
internal TokenHandler() { tokensController = new TokensController(); }
private string ParseForm(string template) { bool hasOptions = false; template = "<%@ Register TagPrefix=\"am\" Namespace=\"DotNetNuke.Modules.ActiveForums.Controls\" Assembly=\"DotNetNuke.Modules.ActiveForums\" %>" + template; template = "<%@ register src=\"~/DesktopModules/ActiveForums/controls/af_posticonlist.ascx\" tagprefix=\"af\" tagname=\"posticons\" %>" + template; template = template.Replace("[AF:INPUT:SUBJECT]", "<asp:textbox id=\"txtSubject\" cssclass=\"aftextbox\" runat=\"server\" />"); template = template.Replace("[AF:REQ:SUBJECT]", "<asp:requiredfieldvalidator id=\"reqSubject\" validationgroup=\"afform\" ControlToValidate=\"txtSubject\" runat=\"server\" />"); template = template.Replace("[AF:REQ:BODY]", "<asp:label id=\"reqCustomBody\" visible=\"false\" runat=\"server\" />"); if (template.Contains("[AF:BODY:TEMPLATE]")) { BodyTemplate = TemplateUtils.GetTemplateSection(template, "[AF:BODY:TEMPLATE]", "[/AF:BODY:TEMPLATE]"); BodyTemplate = BodyTemplate.Replace("[AF:BODY:TEMPLATE]", string.Empty); BodyTemplate = BodyTemplate.Replace("[/AF:BODY:TEMPLATE]", string.Empty); template = TemplateUtils.ReplaceSubSection(template, string.Empty, "[AF:BODY:TEMPLATE]", "[/AF:BODY:TEMPLATE]"); } if (template.Contains("[TOOLBAR")) { var lit = new LiteralControl(); object sToolbar = DataCache.CacheRetrieve("aftb" + ModuleId); if (sToolbar == null) { sToolbar = Utilities.GetFileContent(SettingKeys.TemplatePath + "ToolBar.txt"); sToolbar = Utilities.ParseToolBar(sToolbar.ToString(), TabId, ModuleId, UserId, CurrentUserType); DataCache.CacheStore("aftb" + ModuleId, sToolbar); } lit.Text = sToolbar.ToString(); template = template.Replace("[TOOLBAR]", sToolbar.ToString()); } template = template.Replace("[AF:INPUT:SUMMARY]", "<asp:textbox id=\"txtSummary\" runat=\"server\" />"); template = template.Replace("[AF:INPUT:BODY]", "<asp:placeholder id=\"plhEditor\" runat=\"server\" />"); template = template.Replace("[AF:LABEL:SUBJECT]", "<asp:label id=\"lblSubject\" runat=\"server\" />"); if (!Request.IsAuthenticated & (canCreate || canReply)) { if (template.Contains("[AF:UI:ANON]")) { template = template.Replace("[AF:INPUT:USERNAME]", "<asp:textbox id=\"txtUsername\" cssclass=\"aftextbox\" runat=\"server\" />"); template = template.Replace("[AF:REQ:USERNAME]", "<asp:requiredfieldvalidator id=\"reqUsername\" validationgroup=\"afform\" ControlToValidate=\"txtUsername\" runat=\"server\" />"); template = "<%@ Register TagPrefix=\"dnn\" Assembly=\"DotNetNuke\" Namespace=\"DotNetNuke.UI.WebControls\"%>" + template; template = template.Replace("[AF:INPUT:CAPTCHA]", "<dnn:captchacontrol id=\"ctlCaptcha\" captchawidth=\"130\" captchaheight=\"40\" cssclass=\"Normal\" runat=\"server\" errorstyle-cssclass=\"NormalRed\" />"); if (!RequireCaptcha) { template = template.Replace("[RESX:SecurityCode]:[AF:REQ:SECURITYCODE]", string.Empty); } template = template.Replace("[AF:UI:ANON]", string.Empty); template = template.Replace("[/AF:UI:ANON]", string.Empty); } } else { template = TemplateUtils.ReplaceSubSection(template, string.Empty, "[AF:UI:ANON]", "[/AF:UI:ANON]"); } if (EditorMode != EditorModes.NewTopic || EditorMode != EditorModes.EditTopic) { template = template.Replace("[AF:UI:SECTION:TOPICREVIEW]", "<table class=\"afsection\" cellpadding=\"0\" cellspacing=\"0\"><tr><td class=\"afsectionhd\" style=\"border-left:solid 1px #b3b3b3;\">[RESX:TopicReview]</td><td class=\"afsectionhd\" align=\"right\" style=\"border-right:solid 1px #b3b3b3;\"><img id=\"imgSectionTopicReview\" src=\"" + ImagePath + "/images/arrows_left.png\" border=\"0\" class=\"afarrow\" onclick=\"aftoggleSection('TopicReview');\" /></td></tr><tr><td colspan=\"2\" class=\"afsectiondsp\" id=\"sectionTopicReview\" style=\"display:none;\"><div class=\"affieldsetnote\">[RESX:TopicReview:Note]</div>"); _topicReviewTemplate = TemplateUtils.GetTemplateSection(template, "[AF:CONTROL:TOPICREVIEW]", "[/AF:CONTROL:TOPICREVIEW]"); template = TemplateUtils.ReplaceSubSection(template, "<asp:placeholder id=\"plhTopicReview\" runat=\"server\" />", "[AF:CONTROL:TOPICREVIEW]", "[/AF:CONTROL:TOPICREVIEW]"); template = template.Replace("[/AF:UI:SECTION:TOPICREVIEW]", "</td></tr></table>"); } if (Permissions.HasPerm(ForumInfo.Security.Tag, ForumUser.UserRoles)) { template = template.Replace("[AF:UI:SECTION:TAGS]", "<table class=\"afsection\" cellpadding=\"0\" cellspacing=\"0\"><tr><td class=\"afsectionhd\" style=\"border-left:solid 1px #b3b3b3;\">[RESX:Tags]</td><td class=\"afsectionhd\" align=\"right\" style=\"border-right:solid 1px #b3b3b3;\"><img id=\"imgSectionTags\" src=\"" + ImagePath + "/images/arrows_left.png\" border=\"0\" class=\"afarrow\" onclick=\"aftoggleSection('Tags');\" /></td></tr><tr><td colspan=\"2\" class=\"afsectiondsp\" id=\"sectionTags\" style=\"display:none;\"><div class=\"affieldsetnote\">[RESX:Tags:Note]</div>"); template = template.Replace("[AF:UI:FIELDSET:TAGS]", "<fieldset class=\"affieldset\"><legend>[RESX:Tags]</legend><div class=\"affieldsetnote\">[RESX:Tags:Note]</div>"); var tc = new TokensController(); string sTagOut = tc.TokenGet("editor", "[AF:CONTROL:TAGS]"); if (string.IsNullOrEmpty(sTagOut)) { //sTagOut = "<am:textsuggest id=""tsTags"" runat=""server"" DataTextField=""TagName"" DataValueField=""TagName"" CssResults=""aftsresults"" CssResultItems=""aftsresultsitems"" CssResultItemsSelected=""aftsresultsel"" CssClass=""aftagstxt"" Width=""99%"" />" sTagOut = "<input type=\"text\" id=\"txtTags\" style=\"width:98%;\" class=\"NormalTextBox\" />"; //sTagOut &= "<script type=""text/javascript"">amaf_loadSuggest('txtTags', null, -1);</script>" } sTagOut = sTagOut.Replace("[TAGS]", Tags); template = template.Replace("[AF:CONTROL:TAGS]", sTagOut); template = template.Replace("[/AF:UI:FIELDSET:TAGS]", "</fieldset>"); template = template.Replace("[/AF:UI:SECTION:TAGS]", "</td></tr></table>"); } //Properties if ((EditorMode == EditorModes.EditTopic || EditorMode == EditorModes.NewTopic) & ForumInfo.Properties != null) { string pTemplate = TemplateUtils.GetTemplateSection(template, "[AF:PROPERTIES]", "[/AF:PROPERTIES]"); string propList = string.Empty; foreach (PropertiesInfo p in ForumInfo.Properties) { string pValue = string.Empty; if (TopicProperties != null && TopicProperties.Count > 0) { foreach (PropertiesInfo tp in TopicProperties) { if (tp.PropertyId == p.PropertyId) { pValue = tp.DefaultValue; } } } string tmp = pTemplate; if (p.IsRequired) { tmp = tmp.Replace("[AF:PROPERTY:LABEL]", "<span class=\"afprop-required\">[RESX:" + p.Name + "]</span>"); tmp = tmp.Replace("[AF:PROPERTY:REQUIRED]", "<span class=\"afrequired\"></span>"); } else { tmp = tmp.Replace("[AF:PROPERTY:LABEL]", "<span class=\"afprop-normal\">[RESX:" + p.Name + "]</span>"); tmp = tmp.Replace("[AF:PROPERTY:REQUIRED]", string.Empty); } if (p.DataType == "text") { tmp = tmp.Replace("[AF:PROPERTY:CONTROL]", "<input type=\"text\" id=\"afprop-" + p.PropertyId.ToString() + "\" class=\"NormalTextBox afprop-input\" name=\"afprop-" + p.PropertyId + "\" value=\"" + pValue + "\" />"); } else if (p.DataType == "yesno") { string sYesSelected = string.Empty; string sNoSelected = " checked=\"checked\""; if (pValue.ToLowerInvariant() == "yes") { sYesSelected = " checked=\"checked\""; sNoSelected = string.Empty; } tmp = tmp.Replace("[AF:PROPERTY:CONTROL]", "[RESX:Yes]:<input type=\"radio\" id=\"afprop-" + p.PropertyId.ToString() + "-yes\" groupname=\"afprop-" + p.PropertyId.ToString() + "\" class=\"NormalTextBox afprop-radio\" name=\"afprop-" + p.PropertyId + "\" value=\"Yes\" " + sYesSelected + " /> [RESX:No]:<input type=\"radio\" id=\"afprop-" + p.PropertyId.ToString() + "-no\" groupname=\"afprop-" + p.PropertyId.ToString() + "\" class=\"NormalTextBox afprop-radio\" name=\"afprop-" + p.PropertyId + "\" value=\"No\" " + sNoSelected + " />"); } else if (p.DataType.Contains("list")) { string sList = string.Empty; var lists = new Common.Lists.ListController(); if (p.DataType.Contains("list|")) { sList = "<select id=\"afprop-" + p.PropertyId.ToString() + "\" class=\"NormalTextBox afprop-select\" name=\"afprop-" + p.PropertyId.ToString() + "\">"; string lName = p.DataType.Substring(p.DataType.IndexOf("|") + 1); var lc = lists.GetListEntryInfoCollection(lName, string.Empty); foreach (Common.Lists.ListEntryInfo l in lc) { if (pValue == l.Value) { sList += "<option value=\"" + l.Value + "\" selected=\"selected\">" + l.Text + "</option>"; } else { sList += "<option value=\"" + l.Value + "\">" + l.Text + "</option>"; } } sList += "</select>"; } else if (p.DataType.Contains("list-multi|")) { sList = "<div class=\"afprop-chklist\">"; sList += "<ul>"; string lName = p.DataType.Substring(p.DataType.IndexOf("|") + 1); var lc = lists.GetListEntryInfoCollection(lName, string.Empty); string[] pValues = null; if (!(string.IsNullOrEmpty(pValue))) { pValues = pValue.Split(','); } foreach (Common.Lists.ListEntryInfo l in lc) { bool isSelected = false; if (pValues != null) { foreach (string pv in pValues) { if (pv == l.Value) { isSelected = true; } } } sList += "<li>"; if (isSelected) { sList += "<input type=\"checkbox\" name=\"afprop-" + p.PropertyId.ToString() + "\" value=\"" + l.Value + "\" checked=\"checked\" />"; } else { sList += "<input type=\"checkbox\" name=\"afprop-" + p.PropertyId.ToString() + "\" value=\"" + l.Value + "\" />"; } sList += "<span>" + l.Text + "</span></li>"; } sList += "</ul></div>"; } tmp = tmp.Replace("[AF:PROPERTY:CONTROL]", sList); } propList += tmp; } template = TemplateUtils.ReplaceSubSection(template, propList, "[AF:PROPERTIES]", "[/AF:PROPERTIES]"); } else { template = TemplateUtils.ReplaceSubSection(template, string.Empty, "[AF:PROPERTIES]", "[/AF:PROPERTIES]"); } if ((EditorMode == EditorModes.EditTopic || EditorMode == EditorModes.NewTopic) && Permissions.HasPerm(ForumInfo.Security.Categorize, ForumUser.UserRoles)) { template = template.Replace("[AF:UI:SECTION:CATEGORIES]", "<table class=\"afsection\" cellpadding=\"0\" cellspacing=\"0\"><tr><td class=\"afsectionhd\" style=\"border-left:solid 1px #b3b3b3;\">[RESX:Categories]</td><td class=\"afsectionhd\" align=\"right\" style=\"border-right:solid 1px #b3b3b3;\"><img id=\"imgSectionCategories\" src=\"" + ImagePath + "/images/arrows_left.png\" border=\"0\" class=\"afarrow\" onclick=\"aftoggleSection('Categories');\" /></td></tr><tr><td colspan=\"2\" class=\"afsectiondsp\" id=\"sectionCategories\" style=\"display:none;\"><div class=\"affieldsetnote\">[RESX:Categories:Note]</div>"); template = template.Replace("[AF:UI:FIELDSET:CATEGORIES]", "<fieldset class=\"affieldset\"><legend>[RESX:Categories]</legend><div class=\"affieldsetnote\">[RESX:Categories:Note]</div>"); string sCatOut; var cc = new CategoriesList(PortalId, ModuleId, ForumInfo.ForumID, ForumInfo.ForumGroupId); if (TopicId > 0) { cc.SelectedValues = Categories; } sCatOut = cc.RenderEdit(); template = template.Replace("[AF:CONTROL:CATEGORIES]", sCatOut); template = template.Replace("[/AF:UI:FIELDSET:CATEGORIES]", "</fieldset>"); template = template.Replace("[/AF:UI:SECTION:CATEGORIES]", "</td></tr></table>"); } if ((EditorMode == EditorModes.EditTopic || EditorMode == EditorModes.NewTopic) && Permissions.HasPerm(ForumInfo.Security.Poll, ForumUser.UserRoles)) { template = "<%@ register src=\"~/DesktopModules/ActiveForums/controls/af_polledit.ascx\" tagprefix=\"af\" tagname=\"polledit\" %>" + template; template = template.Replace("[AF:UI:SECTION:POLL]", "<table class=\"afsection\" cellpadding=\"0\" cellspacing=\"0\"><tr><td class=\"afsectionhd\" style=\"border-left:solid 1px #b3b3b3;\">[RESX:Polls]</td><td class=\"afsectionhd\" align=\"right\" style=\"border-right:solid 1px #b3b3b3;\"><img id=\"imgSectionPoll\" src=\"" + ImagePath + "/images/arrows_left.png\" border=\"0\" class=\"afarrow\" onclick=\"aftoggleSection('Poll');\" /></td></tr><tr><td colspan=\"2\" class=\"afsectiondsp\" id=\"sectionPoll\" style=\"display:none;\"><div class=\"affieldsetnote\">[RESX:Poll:Note]</div>"); template = template.Replace("[/AF:UI:SECTION:POLL]", "</td></tr></table>"); template = template.Replace("[AF:UI:FIELDSET:POLL]", "<fieldset class=\"affieldset\"><legend>[RESX:Polls]</legend><div class=\"affieldsetnote\">[RESX:Poll:Note]</div>"); template = template.Replace("[AF:CONTROL:POLL]", "<af:polledit id=\"afpolledit\" runat=\"server\" />"); template = template.Replace("[/AF:UI:FIELDSET:POLL]", "</fieldset>"); template = template.Replace("[AF:CONTROLS:SECTIONTOGGLE]", "<img id=\"imgSectionPoll\" src=\"" + ImagePath + "/images/arrows_left.png\" border=\"0\" class=\"afarrow\" onclick=\"aftoggleSection('Poll');\" />"); } else { template = TemplateUtils.ReplaceSubSection(template, string.Empty, "[AF:UI:FIELDSET:POLL]", "[/AF:UI:FIELDSET:POLL]"); template = template.Replace("[AF:CONTROL:POLL]", string.Empty); } if (EditorMode == EditorModes.ReplyWithBody) { template = template.Replace("[AF:UI:MESSAGEREPLY]", string.Empty); template = template.Replace("[/AF:UI:MESSAGEREPLY]", string.Empty); template = template.Replace("[AF:LABEL:BODYREPLY]", Body); } else { template = TemplateUtils.ReplaceSubSection(template, string.Empty, "[AF:UI:MESSAGEREPLY]", "[/AF:UI:MESSAGEREPLY]"); } if (template.Contains("[AF:UI:FIELDSET:OPTIONS]")) { template = template.Replace("[AF:UI:FIELDSET:OPTIONS]", "<fieldset class=\"affieldset\"><legend>[RESX:AdditionalOptions]</legend>"); template = template.Replace("[/AF:UI:FIELDSET:OPTIONS]", "</fieldset>"); } string sOptions = GetOptions(); template = template.Replace("[AF:CONTROL:OPTIONS]", sOptions); if (template.Contains("[AF:UI:SECTION:OPTIONS]")) { if (sOptions == string.Empty) { template = template.Replace("[AF:UI:SECTION:OPTIONS]", string.Empty); template = template.Replace("[/AF:UI:SECTION:OPTIONS]", string.Empty); } else { template = template.Replace("[AF:UI:SECTION:OPTIONS]", "<table class=\"afsection\" cellpadding=\"0\" cellspacing=\"0\"><tr><td class=\"afsectionhd\" style=\"border-left:solid 1px #b3b3b3;\">[RESX:AdditionalOptions]</td><td class=\"afsectionhd\" align=\"right\" style=\"border-right:solid 1px #b3b3b3;\"><img id=\"imgSectionOptions\" src=\"" + ImagePath + "/images/arrows_left.png\" border=\"0\" class=\"afarrow\" onclick=\"aftoggleSection('Options');\" /></td></tr><tr><td colspan=\"2\" class=\"afsectiondsp\" id=\"sectionOptions\" style=\"display:none;\"><div class=\"affieldsetnote\">[RESX:Options:Note]</div>"); template = template.Replace("[/AF:UI:SECTION:OPTIONS]", "</td></tr></table>"); } } if (template.Contains("[AF:CONTROL:STATUS]")) { if (EditorMode == EditorModes.EditTopic || EditorMode == EditorModes.NewTopic) { template = "<%@ register src=\"~/DesktopModules/ActiveForums/controls/af_topicstatus.ascx\" tagprefix=\"af\" tagname=\"topicstatus\" %>" + template; template = template.Replace("[AF:CONTROL:STATUS]", "<af:topicstatus id=\"aftopicstatus\" AutoPostBack=\"False\" ForumId=\"" + ForumInfo.ForumID + "\" runat=\"server\" />"); } } template = template.Replace("[AF:LINK:FORUMNAME]", "<a href=\"" + NavigateUrl(TabId, "", ParamKeys.ViewType + "=" + Views.Topics + "&" + ParamKeys.ForumId + "=" + ForumInfo.ForumID.ToString()) + "\">" + ForumInfo.ForumName + "</a>"); template = template.Replace("[AF:LINK:FORUMGROUP]", "<a href=\"" + NavigateUrl(TabId, "", ParamKeys.GroupId + "=" + ForumInfo.ForumGroupId.ToString()) + "\">" + ForumInfo.GroupName + "</a>"); template = template.Replace("[AF:LINK:FORUMMAIN]", "<a href=\"" + NavigateUrl(TabId) + "\">[RESX:FORUMS]</a>"); template = !(TopicId == -1) ? template.Replace("[AF:LINK:TOPICNAME]", "<a href=\"" + NavigateUrl(TabId, "", ParamKeys.TopicId + "=" + TopicId + "&" + ParamKeys.ViewType + "=" + Views.Topic + "&" + ParamKeys.ForumId + "=" + ForumInfo.ForumID.ToString()) + "\">" + TopicSubject + "</a>") : template.Replace("[AF:LINK:TOPICNAME]", string.Empty); template = template.Replace("[AF:UI:FIELDSET:ACTIONS]", "<fieldset class=\"affieldset\"><legend>[RESX:Actions]</legend>"); template = template.Replace("[/AF:UI:FIELDSET:ACTIONS]", "</fieldset>"); template = template.Replace("[AF:BUTTON:SUBMIT]", "<am:imagebutton id=\"btnPost\" Text=\"[RESX:Submit]\" runat=\"server\" />"); template = template.Replace("[AF:BUTTON:CANCEL]", "<am:imagebutton id=\"btnCancel\" Text=\"[RESX:Cancel]\" runat=\"server\" />"); template = template.Replace("[AF:BUTTON:PREVIEW]", Request.IsAuthenticated ? "<am:imagebutton id=\"btnPreview\" PostBack=\"False\" Text=\"[RESX:Preview]\" runat=\"server\" />" : string.Empty); if (template.Contains("[AF:CONTROL:POSTICONS]") && ForumInfo.AllowPostIcon) { template = template.Replace("[AF:UI:FIELDSET:POSTICONS]", "<fieldset class=\"affieldset\"><legend>[RESX:PostIcons]</legend><div class=\"affieldsetnote\">[RESX:PostIcons:Note]</div>"); template = template.Replace("[AF:CONTROL:POSTICONS]", "<af:posticons id=\"afposticons\" runat=\"server\" Theme=\"" + MainSettings.Theme + "\" />"); template = template.Replace("[/AF:UI:FIELDSET:POSTICONS]", "</fieldset>"); } else { template = template.Replace("[AF:UI:FIELDSET:POSTICONS]", string.Empty); template = template.Replace("[AF:CONTROL:POSTICONS]", string.Empty); template = template.Replace("[/AF:UI:FIELDSET:POSTICONS]", string.Empty); } if (template.Contains("[AF:CONTROL:EMOTICONS]") && ForumInfo.AllowEmoticons) { var objUtils = new emoticons(); //Dim obj As Object = DataCache.CacheRetrieve(ForumModuleId & "Emoticons" & EditorType.ToString) //If obj Is Nothing Then // DataCache.CacheStore(ForumModuleId & "Emoticons" & EditorType.ToString) = objUtils.LoadEmoticons(EditorType, ForumModuleId, ImagePath) //End If template = template.Replace("[AF:CONTROL:EMOTICONS]", "<fieldset class=\"affieldset\"><legend>[RESX:Smilies]</legend>" + objUtils.LoadEmoticons(EditorType, ModuleId, ImagePath) + "</fieldset>"); } else { template = template.Replace("[AF:CONTROL:EMOTICONS]", string.Empty); } if (template.Contains("[AF:CONTROL:UPLOAD]")) { if (canAttach && ForumInfo.AllowAttach) { template = "<%@ register src=\"~/DesktopModules/ActiveForums/controls/af_attach.ascx\" tagprefix=\"af\" tagname=\"attach\" %>" + template; template = template.Replace("[AF:UI:FIELDSET:ATTACH]", "<fieldset class=\"affieldset\"><legend>[RESX:Attachments]</legend><div class=\"affieldsetnote\">[RESX:Attacments:Note]</div>"); template = template.Replace("[AF:UI:SECTION:ATTACH]", "<table class=\"afsection\" cellpadding=\"0\" cellspacing=\"0\"><tr><td class=\"afsectionhd\" style=\"border-left:solid 1px #b3b3b3;\">[RESX:Attachments]</td><td class=\"afsectionhd\" align=\"right\" style=\"border-right:solid 1px #b3b3b3;\"><img id=\"imgSectionAttach\" src=\"" + ImagePath + "/images/arrows_left.png\" border=\"0\" class=\"afarrow\" onclick=\"aftoggleSection('Attach');\" /></td></tr><tr><td colspan=\"2\" class=\"afsectiondsp\" id=\"sectionAttach\" style=\"display:none;\"><div class=\"affieldsetnote\">[RESX:Attachments:Note]</div>"); template = template.Replace("[AF:CONTROL:UPLOAD]", "<af:attach id=\"ctlAttach\" runat=\"server\" />"); template = template.Replace("[/AF:UI:FIELDSET:ATTACH]", "</fieldset>"); template = template.Replace("[/AF:UI:SECTION:ATTACH]", "</td></tr></table>"); } else { template = template.Replace("[AF:UI:FIELDSET:ATTACH]", string.Empty); template = template.Replace("[AF:CONTROL:UPLOAD]", string.Empty); template = template.Replace("[/AF:UI:FIELDSET:ATTACH]", string.Empty); template = template.Replace("[AF:UI:SECTION:ATTACH]", string.Empty); template = template.Replace("[/AF:UI:SECTION:ATTACH]", string.Empty); } } //If str.Contains("[AF:CONTROL:FORUMTREE]") Then // str = str.Replace("[AF:CONTROL:FORUMTREE]", "<af:forumtree id=""ctlForumTree"" runat=""server"" showcheckboxes=""true"" ModuleId=""" & ModuleId & """ />") // sHeader &= "<%@ register src=""~/DesktopModules/ActiveForums/controls/af_forumtree.ascx"" tagprefix=""af"" tagname=""forumtree"" %>" //End If template = Utilities.LocalizeControl(template); template = Utilities.StripTokens(template); return template; }
/* private void LinkControls(ControlCollection ctrls) { foreach (Control ctrl in ctrls) { if ((ctrl) is ForumBase) { ((ForumBase)ctrl).ModuleConfiguration = this.ModuleConfiguration; ((ForumBase)ctrl).TopicId = TopicId; } if (ctrl.Controls.Count > 0) { LinkControls(ctrl.Controls); } } }*/ private string ParseControls(string sOutput) { // Do a few things before we switch to a string builder // Add This if (sOutput.Contains("[AF:CONTROL:ADDTHIS")) { var strHost = Common.Globals.AddHTTP(Common.Globals.GetDomainName(Request)); sOutput = TemplateUtils.ParseSpecial(sOutput, SpecialTokenTypes.AddThis, strHost + Request.RawUrl, _topicSubject, _bRead, MainSettings.AddThisAccount); } // Banners if (sOutput.Contains("[BANNER")) { sOutput = sOutput.Replace("[BANNER]", "<dnn:BANNER runat=\"server\" GroupName=\"FORUMS\" BannerCount=\"1\" EnableViewState=\"False\" />"); const string pattern = @"(\[BANNER:(.+?)\])"; const string sBanner = "<dnn:BANNER runat=\"server\" BannerCount=\"1\" GroupName=\"$1\" EnableViewState=\"False\" />"; sOutput = Regex.Replace(sOutput, pattern, sBanner); } // Now use the string builder to do all replacements var sbOutput = new StringBuilder(sOutput); if (Request.QueryString["dnnprintmode"] != null) { sbOutput.Replace("[ADDREPLY]", string.Empty); sbOutput.Replace("[QUICKREPLY]", string.Empty); sbOutput.Replace("[TOPICSUBSCRIBE]", string.Empty); sbOutput.Replace("[AF:CONTROL:PRINTER]", string.Empty); sbOutput.Replace("[AF:CONTROL:EMAIL]", string.Empty); sbOutput.Replace("[PAGER1]", string.Empty); sbOutput.Replace("[PAGER2]", string.Empty); sbOutput.Replace("[SORTDROPDOWN]", string.Empty); sbOutput.Replace("[POSTRATINGBUTTON]", string.Empty); sbOutput.Replace("[JUMPTO]", string.Empty); sbOutput.Replace("[NEXTTOPIC]", string.Empty); sbOutput.Replace("[PREVTOPIC]", string.Empty); sbOutput.Replace("[AF:CONTROL:STATUS]", string.Empty); sbOutput.Replace("[ACTIONS:DELETE]", string.Empty); sbOutput.Replace("[ACTIONS:EDIT]", string.Empty); sbOutput.Replace("[ACTIONS:QUOTE]", string.Empty); sbOutput.Replace("[ACTIONS:REPLY]", string.Empty); sbOutput.Replace("[ACTIONS:ANSWER]", string.Empty); sbOutput.Replace("[ACTIONS:ALERT]", string.Empty); sbOutput.Replace("[RESX:SortPosts]:", string.Empty); sbOutput.Append("<img src=\"~/desktopmodules/activeforums/images/spacer.gif\" width=\"800\" height=\"1\" runat=\"server\" alt=\"---\" />"); } sbOutput.Replace("[NOPAGING]", "<script type=\"text/javascript\">afpagesize=" + int.MaxValue + ";</script>"); sbOutput.Replace("[NOTOOLBAR]", string.Empty); // Subscribe Option if (_bSubscribe) { var subControl = new ToggleSubscribe(1, ForumId, TopicId); subControl.Checked = _isSubscribedTopic; subControl.Text = "[RESX:TopicSubscribe:" + _isSubscribedTopic.ToString().ToUpper() + "]"; sbOutput.Replace("[TOPICSUBSCRIBE]", subControl.Render()); } else { sbOutput.Replace("[TOPICSUBSCRIBE]", string.Empty); } // Topic and post actions var tc = new TokensController(); var topicActions = tc.TokenGet("topic", "[AF:CONTROL:TOPICACTIONS]"); var postActions = tc.TokenGet("topic", "[AF:CONTROL:POSTACTIONS]"); if (sOutput.Contains("[AF:CONTROL:TOPICACTIONS]")) { _useListActions = true; sbOutput.Replace("[AF:CONTROL:TOPICACTIONS]", topicActions); sbOutput.Replace("[AF:CONTROL:POSTACTIONS]", postActions); } // Quick Reply if (_bLocked) { sbOutput.Replace("[ADDREPLY]", "<span class=\"afnormal\">[RESX:TopicLocked]</span>"); sbOutput.Replace("[QUICKREPLY]", string.Empty); } else { //TODO: Check for owner if (CanReply) { var @params = new List<string> { ParamKeys.ViewType + "=post", ParamKeys.TopicId + "=" + TopicId, ParamKeys.ForumId + "=" + ForumId }; if (SocialGroupId > 0) @params.Add("GroupId=" + SocialGroupId); sbOutput.Replace("[ADDREPLY]", "<a href=\"" + Utilities.NavigateUrl(TabId, "", @params.ToArray()) + "\" class=\"dnnPrimaryAction\">[RESX:AddReply]</a>"); sbOutput.Replace("[QUICKREPLY]", "<asp:placeholder id=\"plhQuickReply\" runat=\"server\" />"); } else { sbOutput.Replace("[ADDREPLY]", "<span class=\"afnormal\">[RESX:NotAuthorizedReply]</span>"); sbOutput.Replace("[QUICKREPLY]", string.Empty); } } // Parent Forum Link if (sOutput.Contains("[PARENTFORUMLINK]")) { if (ForumInfo.ParentForumId > 0) { if (MainSettings.UseShortUrls) sbOutput.Replace("[PARENTFORUMLINK]", "<a href=\"" + Utilities.NavigateUrl(TabId, "", new[] { ParamKeys.ForumId + "=" + ForumInfo.ParentForumId }) + "\">" + ForumInfo.ParentForumName + "</a>"); else sbOutput.Replace("[PARENTFORUMLINK]", "<a href=\"" + Utilities.NavigateUrl(TabId, "", new[] { ParamKeys.ViewType + "=" + Views.Topics, ParamKeys.ForumId + "=" + ForumInfo.ParentForumId }) + "\">" + ForumInfo.ParentForumName + "</a>"); } else if (ForumInfo.ForumGroupId > 0) sbOutput.Replace("[PARENTFORUMLINK]", "<a href=\"" + Utilities.NavigateUrl(TabId) + "\">" + ForumInfo.GroupName + "</a>"); } // Parent Forum Name if (string.IsNullOrEmpty(ForumInfo.ParentForumName)) sbOutput.Replace("[PARENTFORUMNAME]", ForumInfo.ParentForumName); // ForumLinks sbOutput.Replace("[FORUMMAINLINK]", "<a href=\"" + Utilities.NavigateUrl(TabId) + "\">[RESX:ForumMain]</a>"); sbOutput.Replace("[FORUMGROUPLINK]", "<a href=\"" + Utilities.NavigateUrl(TabId, "", ParamKeys.GroupId + "=" + ForumGroupId) + "\">" + _groupName + "</a>"); if (MainSettings.UseShortUrls) sbOutput.Replace("[FORUMLINK]", "<a href=\"" + Utilities.NavigateUrl(TabId, "", ParamKeys.ForumId + "=" + ForumId) + "\">" + _forumName + "</a>"); else sbOutput.Replace("[FORUMLINK]", "<a href=\"" + Utilities.NavigateUrl(TabId, "", ParamKeys.ViewType + "=" + Views.Topics + "&" + ParamKeys.ForumId + "=" + ForumId) + "\">" + _forumName + "</a>"); // Names and Ids sbOutput.Replace("[FORUMID]", ForumId.ToString()); sbOutput.Replace("[FORUMNAME]", _forumName); sbOutput.Replace("[GROUPNAME]", _groupName); // Printer Friendly Link var sURL = "<a rel=\"nofollow\" href=\"" + Utilities.NavigateUrl(TabId, "", ParamKeys.ForumId + "=" + ForumId, ParamKeys.ViewType + "=" + Views.Topic, ParamKeys.TopicId + "=" + TopicId, "mid=" + ModuleId, "dnnprintmode=true") + "?skinsrc=" + HttpUtility.UrlEncode("[G]" + UI.Skins.SkinInfo.RootSkin + "/" + Common.Globals.glbHostSkinFolder + "/" + "No Skin") + "&containersrc=" + HttpUtility.UrlEncode("[G]" + UI.Skins.SkinInfo.RootContainer + "/" + Common.Globals.glbHostSkinFolder + "/" + "No Container") + "\" target=\"_blank\">"; sURL += "<img src=\"" + _myThemePath + "/images/print16.png\" border=\"0\" alt=\"[RESX:PrinterFriendly]\" /></a>"; sbOutput.Replace("[AF:CONTROL:PRINTER]", sURL); // Email Link if (Request.IsAuthenticated) { sURL = Utilities.NavigateUrl(TabId, "", new [] { ParamKeys.ViewType + "=sendto", ParamKeys.ForumId + "=" + ForumId, ParamKeys.TopicId + "=" + TopicId }); sbOutput.Replace("[AF:CONTROL:EMAIL]", "<a href=\"" + sURL + "\" rel=\"nofollow\"><img src=\"" + _myThemePath + "/images/email16.png\" border=\"0\" alt=\"[RESX:EmailThis]\" /></a>"); } else sbOutput.Replace("[AF:CONTROL:EMAIL]", string.Empty); // RSS Link if (_bAllowRSS) { var url = Common.Globals.AddHTTP(Common.Globals.GetDomainName(Request)) + "/DesktopModules/ActiveForums/feeds.aspx?portalid=" + PortalId + "&forumid=" + ForumId + "&tabid=" + TabId + "&moduleid=" + ModuleId; sbOutput.Replace("[RSSLINK]", "<a href=\"" + url + "\"><img src=\"~/DesktopModules/ActiveForums/themes/" + _myTheme + "/images/rss.png\" runat=server border=\"0\" alt=\"[RESX:RSS]\" /></a>"); } else sbOutput.Replace("[RSSLINK]", string.Empty); // Subject _topicSubject = _topicSubject.Replace("[", "["); _topicSubject = _topicSubject.Replace("]", "]"); sbOutput.Replace("[SUBJECT]", Utilities.StripHTMLTag(_topicSubject)); // Reply Count sbOutput.Replace("[REPLYCOUNT]", _replyCount.ToString()); sbOutput.Replace("[AF:LABEL:ReplyCount]", _replyCount.ToString()); // View Count sbOutput.Replace("[VIEWCOUNT]", _viewCount.ToString()); // Last Post sbOutput.Replace("[AF:LABEL:LastPostDate]", _lastPostDate); sbOutput.Replace("[AF:LABEL:LastPostAuthor]", UserProfiles.GetDisplayName(ModuleId, true, _bModApprove, ForumUser.IsAdmin || ForumUser.IsSuperUser, _lastPostAuthor.AuthorId, _lastPostAuthor.Username, _lastPostAuthor.FirstName, _lastPostAuthor.LastName, _lastPostAuthor.DisplayName)); // Topic Info sbOutput.Replace("[AF:LABEL:TopicAuthor]", UserProfiles.GetDisplayName(ModuleId, _topicAuthorId, _topicAuthorDisplayName, string.Empty, string.Empty, _topicAuthorDisplayName)); sbOutput.Replace("[AF:LABEL:TopicDateCreated]", _topicDateCreated); // Pagers if (_pageSize == int.MaxValue) { sbOutput.Replace("[PAGER1]", string.Empty); sbOutput.Replace("[PAGER2]", string.Empty); } else { sbOutput.Replace("[PAGER1]", "<am:pagernav id=\"Pager1\" runat=\"server\" EnableViewState=\"False\" />"); sbOutput.Replace("[PAGER2]", "<am:pagernav id=\"Pager2\" runat=\"server\" EnableViewState=\"False\" />"); } // Sort sbOutput.Replace("[SORTDROPDOWN]", "<asp:placeholder id=\"plhTopicSort\" runat=\"server\" />"); var rateControl = new Ratings(TopicId, true, _topicRating); sbOutput.Replace("[POSTRATINGBUTTON]", rateControl.Render()); // Jump To sbOutput.Replace("[JUMPTO]", "<asp:placeholder id=\"plhQuickJump\" runat=\"server\" />"); // Next Topic if (_nextTopic == 0) sbOutput.Replace("[NEXTTOPIC]", string.Empty); else { if (MainSettings.UseShortUrls) sbOutput.Replace("[NEXTTOPIC]", "<a href=\"" + Utilities.NavigateUrl(TabId, "", ParamKeys.TopicId + "=" + _nextTopic) + "\" rel=\"nofollow\"><span>[RESX:NextTopic]</span><img src=\"~/DesktopModules/ActiveForums/themes/" + _myTheme + "/images/arrow_right_blue.gif\" runat=server style=\"vertical-align:middle;\" border=\"0\" alt=\"[RESX:NextTopic]\" /></a>"); else sbOutput.Replace("[NEXTTOPIC]", "<a href=\"" + Utilities.NavigateUrl(TabId, "", ParamKeys.ForumId + "=" + ForumId + "&" + ParamKeys.TopicId + "=" + _nextTopic + "&" + ParamKeys.ViewType + "=" + Views.Topic) + "\" rel=\"nofollow\"><span>[RESX:NextTopic]</span><img src=\"~/DesktopModules/ActiveForums/themes/" + _myTheme + "/images/arrow_right_blue.gif\" runat=server style=\"vertical-align:middle;\" border=\"0\" alt=\"[RESX:NextTopic]\" /></a>"); } // Previous Topic if (_prevTopic == 0) sbOutput.Replace("[PREVTOPIC]", string.Empty); else { if (MainSettings.UseShortUrls) sbOutput.Replace("[PREVTOPIC]", "<a href=\"" + Utilities.NavigateUrl(TabId, "", ParamKeys.TopicId + "=" + _prevTopic) + "\" rel=\"nofollow\"><img src=\"~/DesktopModules/ActiveForums/themes/" + _myTheme + "/images/arrow_left_blue.gif\" runat=server style=\"vertical-align:middle;\" border=\"0\" alt=\"[RESX:PrevTopic]\" /><span>[RESX:PrevTopic]</span></a>"); else sbOutput.Replace("[PREVTOPIC]", "<a href=\"" + Utilities.NavigateUrl(TabId, "", ParamKeys.ForumId + "=" + ForumId + "&" + ParamKeys.TopicId + "=" + _prevTopic + "&" + ParamKeys.ViewType + "=" + Views.Topic) + "\" rel=\"nofollow\"><img src=\"~/DesktopModules/ActiveForums/themes/" + _myTheme + "/images/arrow_left_blue.gif\" runat=server style=\"vertical-align:middle;\" border=\"0\" alt=\"[RESX:PrevTopic]\" /><span>[RESX:PrevTopic]</span></a>"); } // Topic Status if (((_bRead && _topicAuthorId == UserId) || _bModEdit) & _statusId >= 0) { sbOutput.Replace("[AF:CONTROL:STATUS]", "<asp:placeholder id=\"plhStatus\" runat=\"server\" />"); sbOutput.Replace("[AF:CONTROL:STATUSICON]", "<img alt=\"[RESX:PostStatus" + _statusId.ToString() + "]\" src=\"" + _myThemePath + "/images/status" + _statusId.ToString() + ".png\" />"); } else if (_statusId >= 0) { sbOutput.Replace("[AF:CONTROL:STATUS]", string.Empty); sbOutput.Replace("[AF:CONTROL:STATUSICON]", "<img alt=\"[RESX:PostStatus" + _statusId.ToString() + "]\" src=\"" + _myThemePath + "/images/status" + _statusId.ToString() + ".png\" />"); } else { sbOutput.Replace("[AF:CONTROL:STATUS]", string.Empty); sbOutput.Replace("[AF:CONTROL:STATUSICON]", string.Empty); } // Poll if (_topicType == (int)TopicTypes.Poll) sbOutput.Replace("[AF:CONTROL:POLL]", "<asp:placeholder id=\"plhPoll\" runat=\"server\" />"); else sbOutput.Replace("[AF:CONTROL:POLL]", string.Empty); return sbOutput.ToString(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllersWithViews() .AddNewtonsoftJson(options => { // Return JSON responses in LowerCase? options.SerializerSettings.ContractResolver = new DefaultContractResolver(); // Resolve Looping navigation properties options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; }); services.AddDbContext <AtTempleteWebContext>(options => options.UseSqlServer( Configuration.GetConnectionString("DefaultConnection"))); // Register the Swagger generator, defining 1 or more Swagger documents services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Version = "v1", Title = "Template WEBSITE", Description = "A simple example ASP.NET Core Web API", TermsOfService = new Uri("https://example.com/terms"), Contact = new OpenApiContact { Name = "Shayne Boyer", Email = string.Empty, Url = new Uri("https://twitter.com/spboyer"), }, License = new OpenApiLicense { Name = "Use under LICX", Url = new Uri("https://example.com/license"), } }); // JWT-token authentication by password c.OperationFilter <AuthResponsesOperationFilter>(); c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { Name = "Authorization", Description = "JWT Authorization header using the Bearer scheme.", Scheme = "bearer", BearerFormat = "JWT", In = ParameterLocation.Header, Type = SecuritySchemeType.Http }); var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); c.IncludeXmlComments(xmlPath); }); services.AddControllers(); services.AddAuthentication() .AddJwtBearer(cfg => { //cfg.RequireHttpsMetadata = false; //cfg.SaveToken = true; cfg.TokenValidationParameters = TokensController.GetTokenValidationParameters(Configuration, true); cfg.Events = new JwtBearerEvents { OnTokenValidated = async context => { var jwtToken = (JwtSecurityToken)context.SecurityToken; var userId = TokensController.GetClaimsUserId(jwtToken.Claims); var device = TokensController.GetClaimsDevice(jwtToken.Claims); var accessToken = TokensController.GetCacheAccessTokenAsync(Cache, userId, device); if (context.SecurityToken.Id != accessToken) { var refreshToken = TokensController.GetCacheRefreshTokenAsync(Cache, userId, device); if (string.IsNullOrWhiteSpace(refreshToken)) { context.Response.Headers.Add("Token-Revoked", "Access-Refresh"); context.Fail("Token-Revoked-Access-Refresh"); } else { context.Response.Headers.Add("Token-Revoked", "Access"); context.Fail("Token-Revoked-Access"); } } return; }, OnAuthenticationFailed = async context => { if (context.Exception.GetType() == typeof(SecurityTokenExpiredException)) { if (context.Principal != null) { context.Response.Headers.Add("Token-Expired", "Access"); var userId = TokensController.GetClaimsUserId(context.Principal.Claims); var device = TokensController.GetClaimsDevice(context.Principal.Claims); var refreshToken = TokensController.GetCacheRefreshTokenAsync(Cache, userId, device); if (string.IsNullOrWhiteSpace(refreshToken)) { context.Response.Headers.Add("Token-Revoked", "Refresh"); } } } } }; }); ; services.AddMemoryCache(); // Đăng ký logic services.AddScoped <AtLoginLogic>(); services.AddScoped <AtBaseLogic>(); services.AddScoped <AtInformationUserLogic>(); services.AddScoped <AtAccountObjectLogic>(); services.AddScoped <AtPermissionMenuFunctionLogic>(); services.AddScoped <AtRoleLogic>(); services.AddScoped <AtDepartmentLogic>(); services.AddScoped <AtMenuFuntionLogic>(); services.AddScoped <AtMenuFunctionSubGroupLogic>(); services.AddScoped <AtSettingLogic>(); services.AddCors(options => { options.AddPolicy(MyAllowSpecificOrigins, builder => builder .AllowAnyOrigin() .AllowAnyHeader() .AllowAnyMethod() ); }); // Validators Controller AcccountObject services.AddSingleton <IValidator <AccountObjectDmInput_Create>, AccountObjectCreateVd>(); services.AddSingleton <IValidator <AccountObjectDmInput_Edit>, AccountObjectEditVd>(); services.AddSingleton <IValidator <AccountObjectDm_ResetPassword>, ResetPasswordVd>(); services.AddSingleton <IValidator <AccountObjectDm_UpdatePass>, ModifyPassword>(); services.AddSingleton <IValidator <AccountObjectDm_UpdateAccount>, AccountObjectUpdateInfromation>(); services.AddSingleton <IValidator <AccountObjectDm_Delete>, AccountObjectDeleteVd>(); //Validators Controller Role services.AddSingleton <IValidator <AtRoleDmInputCreate>, RoleCreateVd>(); services.AddSingleton <IValidator <AtRoleDmInputEdit>, AtRoleEditVd>(); services.AddSingleton <IValidator <AtRoleDmInputDelete>, AtRoleDeleteVd>(); //Validation Controller Setting services.AddSingleton <IValidator <AtSettingDmCreateInput>, AtSettingCreateVd>(); services.AddSingleton <IValidator <AtSettingDmEditInput>, AtSettingEditVd>(); services.AddSingleton <IValidator <AtSettingDmInputDelete>, AtSettingDeleteVd>(); //Validator Controller MenuFunction services.AddSingleton <IValidator <MenuFunctionDmCreatetInputOrEdit>, MenuFunctionCreatetOrEditVd>(); // mvc + validating services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0).AddFluentValidation(); // override modelstate services.Configure <ApiBehaviorOptions>(options => { options.InvalidModelStateResponseFactory = (context) => { var errors = context.ModelState.Values.SelectMany(x => x.Errors.Select(p => p.ErrorMessage)).ToList(); var result = new { Code = "400", Message = "Validation errors", Errors = errors }; return(new BadRequestObjectResult(result)); }; }); }