public static MvcHtmlString DeleteConfiration <TModel>(this HtmlHelper <TModel> htmlHelper, string actionName, string buttonSelector) where TModel : BaseEntityModel { if (htmlHelper is null) { return(null); } if (string.IsNullOrEmpty(actionName)) { actionName = "Delete"; } string modelId = htmlHelper.ViewData.ModelMetadata.ModelType.Name + "-delete-confiramation"; DeleteConfirmationModel deleteConfirmationModel = new DeleteConfirmationModel() { ActionName = actionName, ControllerName = htmlHelper.ViewContext.RouteData.GetRequiredString("controller"), Id = htmlHelper.ViewData.Model.Id, WindowId = modelId }; StringBuilder window = new StringBuilder(); window.Append(htmlHelper.Partial("Delete", deleteConfirmationModel).ToHtmlString()); window.AppendLine("<script>"); window.AppendLine("$(document).ready(function() {"); window.AppendFormat("$('#{0}').attr(\"data-toggle\", \"modal\").attr(\"data-target\", \"#{1}\")", buttonSelector, modelId); window.AppendLine("});"); window.AppendLine("</script>"); return(MvcHtmlString.Create(window.ToString())); }
public override void Process(TagHelperContext context, TagHelperOutput output) { var href = output.Attributes["href"].Value; var query = new DeleteConfirmationModel { Id = Id, Url = href.ToString(), Title = string.IsNullOrEmpty(Title) ? "Are you sure?" : Title, Body = string.IsNullOrEmpty(Body) ? "Are you sure you want to delete this item?" : Body }; output.Attributes.SetAttribute("href", "#"); output.Attributes.Add("role", "button"); output.Attributes.Add("data-ajax", "true"); output.Attributes.Add("data-ajax-method", "GET"); output.Attributes.Add("data-ajax-url", _urlHelper.Action("RenderDeleteConfirmation", "Shared", query)); output.Attributes.Add("data-ajax-cache", "false"); output.Attributes.Add("data-ajax-success", "handleModalLinkLoaded"); output.Attributes.Add("data-ajax-failure", "handleModalLinkFailed"); output.Attributes.Add("data-ajax-update", "#main-modal div.modal-content"); if (ModalToggle) { output.Attributes.Add("data-toggle", "modal"); output.Attributes.Add("data-target", "#main-modal"); } }
public ActionResult Delete(DeleteConfirmationModel model) { if (!ModelState.IsValid) { return(View("~/Views/Shared/Dialogs/DeleteConfirmation.cshtml", model)); } var repository = CurrentAccountDbContext.GetUnitTestTypeRepository(); var unitTestType = repository.GetById(Guid.Parse(model.Id)); CheckDeletingPermissions(unitTestType); var client = GetDispatcherClient(); var response = client.DeleteUnitTestType(CurrentUser.AccountId, new DeleteUnitTestTypeRequestData() { UnitTestTypeId = unitTestType.Id }); if (!response.Success) { throw new UserFriendlyException(response.ErrorMessage); } this.SetTempMessage(TempMessageType.Success, "Тип проверки удалён"); return(RedirectToAction("Index")); }
public static MvcHtmlString DeleteConfirmation <T>(this HtmlHelper <T> helper, string actionName, string buttonsSelector) where T : BaseQuGoEntityModel { if (String.IsNullOrEmpty(actionName)) { actionName = "Delete"; } var modalId = MvcHtmlString.Create(helper.ViewData.ModelMetadata.ModelType.Name.ToLower() + "-delete-confirmation") .ToHtmlString(); var deleteConfirmationModel = new DeleteConfirmationModel { Id = helper.ViewData.Model.Id, ControllerName = helper.ViewContext.RouteData.GetRequiredString("controller"), ActionName = actionName, WindowId = modalId }; var window = new StringBuilder(); window.AppendLine(string.Format("<div id='{0}' class=\"modal fade\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"{0}-title\">", modalId)); window.AppendLine(helper.Partial("Delete", deleteConfirmationModel).ToHtmlString()); window.AppendLine("</div>"); window.AppendLine("<script>"); window.AppendLine("$(document).ready(function() {"); window.AppendLine(string.Format("$('#{0}').attr(\"data-toggle\", \"modal\").attr(\"data-target\", \"#{1}\")", buttonsSelector, modalId)); window.AppendLine("});"); window.AppendLine("</script>"); return(MvcHtmlString.Create(window.ToString())); }
/// <summary> /// Adds an action name parameter for using other delete action names /// </summary> /// <typeparam name="T"></typeparam> /// <param name="helper"></param> /// <param name="actionName"></param> /// <param name="buttonsSelector"></param> /// <returns></returns> public static MvcHtmlString DeleteConfirmation <T>(this HtmlHelper <T> helper, string actionName, string buttonsSelector = null) where T : EntityModelBase { if (String.IsNullOrEmpty(actionName)) { actionName = "Delete"; } var modalId = MvcHtmlString.Create(helper.ViewData.ModelMetadata.ModelType.Name.ToLower() + "-delete-confirmation").ToHtmlString(); var deleteConfirmationModel = new DeleteConfirmationModel { Id = helper.ViewData.Model.Id, ControllerName = helper.ViewContext.RouteData.GetRequiredString("controller"), ActionName = actionName, ButtonSelector = buttonsSelector, // TODO: (MC) this is really awkward, but sufficient for the moment EntityType = buttonsSelector.Replace("-delete", "") }; var script = string.Empty; if (buttonsSelector.HasValue()) { script = "<script>$(function() { $('#" + modalId + "').modal(); $('#" + buttonsSelector + "').on('click', function(e){e.preventDefault();openModalWindow('" + modalId + "');} ); });</script>\n"; } helper.SmartStore().Window().Name(modalId) .Title(EngineContext.Current.Resolve <ILocalizationService>().GetResource("Admin.Common.AreYouSure")) .Content(helper.Partial("Delete", deleteConfirmationModel).ToHtmlString()) .Show(false) .Render(); return(new MvcHtmlString(script)); }
/// <summary> /// Process /// </summary> /// <param name="context">Context</param> /// <param name="output">Output</param> public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (output == null) { throw new ArgumentNullException(nameof(output)); } //contextualize IHtmlHelper var viewContextAware = _htmlHelper as IViewContextAware; viewContextAware?.Contextualize(ViewContext); if (string.IsNullOrEmpty(Action)) { Action = "Delete"; } var modelName = _htmlHelper.ViewData.ModelMetadata.ModelType.Name.ToLower(); if (!string.IsNullOrEmpty(Action)) { modelName += "-" + Action; } var modalId = new HtmlString(modelName + "-delete-confirmation").ToHtmlString(); if (int.TryParse(ModelId, out int modelId)) { var deleteConfirmationModel = new DeleteConfirmationModel { Id = modelId, ControllerName = _htmlHelper.ViewContext.RouteData.Values["controller"].ToString(), ActionName = Action, WindowId = modalId }; //tag details output.TagName = "div"; output.TagMode = TagMode.StartTagAndEndTag; output.Attributes.Add("id", modalId); output.Attributes.Add("class", "modal fade"); output.Attributes.Add("tabindex", "-1"); output.Attributes.Add("role", "dialog"); output.Attributes.Add("aria-labelledby", $"{modalId}-title"); output.Content.SetHtmlContent(await _htmlHelper.PartialAsync("Delete", deleteConfirmationModel)); //modal script var script = new TagBuilder("script"); script.InnerHtml.AppendHtml("$(document).ready(function () {" + $"$('#{ButtonId}').attr(\"data-toggle\", \"modal\").attr(\"data-target\", \"#{modalId}\")" + "});"); output.PostContent.SetHtmlContent(script.RenderHtmlContent()); } }
public ActionResult Delete(DeleteConfirmationModel model) { var userService = new UserService(DbContext); var user = userService.GetById(CurrentUser.AccountId, Guid.Parse(model.Id)); userService.DeleteUser(user, CurrentUser.AccountId); return(RedirectToAction("Index")); }
public ActionResult Delete(DeleteConfirmationModel model) { if (!ModelState.IsValid) { return(View("~/Views/Shared/Dialogs/DeleteConfirmation.cshtml", model)); } var repository = CurrentAccountDbContext.GetEventTypeRepository(); var eventType = repository.GetById(Guid.Parse(model.Id)); CheckDeletingPermissions(eventType); repository.Remove(eventType); this.SetTempMessage(TempMessageType.Success, "Тип события удалён"); return(RedirectToAction("Index")); }
public override async Task ProcessAsync(TagHelperContext tagHelperContext, TagHelperOutput output) { if (string.IsNullOrEmpty(Action)) { Action = "Delete"; } var windowId = new HtmlString(ViewContext.ViewData.ModelMetadata.ModelType.Name.ToLower() + "-delete-confirmation").ToHtmlString(); var modelId = string.IsNullOrEmpty(ModelId) ? ViewContext.RouteData.Values["Id"].ToString() : ModelId; var deleteConfirmationModel = new DeleteConfirmationModel { Id = modelId, ControllerName = ViewContext.RouteData.Values["controller"].ToString(), ActionName = Action, WindowId = windowId }; (_htmlHelper as IViewContextAware).Contextualize(ViewContext); output.TagName = "div"; output.TagMode = TagMode.StartTagAndEndTag; output.Attributes.SetAttribute("id", windowId); output.Attributes.SetAttribute("style", "display:none"); output.Content.SetHtmlContent((await _htmlHelper.PartialAsync("Delete", deleteConfirmationModel)).ToHtmlString()); var window = new StringBuilder(); window.AppendLine("<script>"); window.AppendLine("$(document).ready(function() {"); window.AppendLine(string.Format("$('#{0}').click(function (e) ", ButtonId)); window.AppendLine("{"); window.AppendLine("e.preventDefault();"); window.AppendLine(string.Format("var window = $('#{0}');", windowId)); window.AppendLine("if (!window.data('kendoWindow')) {"); window.AppendLine("window.kendoWindow({"); window.AppendLine("modal: true,"); window.AppendLine(string.Format("title: '{0}',", _translationService.GetResource("Admin.Common.AreYouSure"))); window.AppendLine("actions: ['Close']"); window.AppendLine("});"); window.AppendLine("}"); window.AppendLine("window.data('kendoWindow').center().open();"); window.AppendLine("});"); window.AppendLine("});"); window.AppendLine("</script>"); output.PostContent.SetHtmlContent(window.ToString()); }
public ActionResult Delete(Guid id) { var repository = CurrentAccountDbContext.GetUserRepository(); var user = repository.GetById(id); var model = new DeleteConfirmationModel() { Id = user.Id.ToString(), Title = "Удаление пользователя", ModalMode = Request.IsAjaxRequest(), Message = "Вы действительно хотите удалить этого пользователя?", ReturnUrl = Url.Action("Index") }; return(View("~/Views/Shared/Dialogs/DeleteConfirmation.cshtml", model)); }
public ActionResult DeleteRule(DeleteConfirmationModel model) { if (!ModelState.IsValid) { return(View("~/Views/Shared/Dialogs/DeleteConfirmation.cshtml", model)); } var repository = CurrentAccountDbContext.GetHttpRequestUnitTestRuleRepository(); var rule = repository.GetById(Guid.Parse(model.Id)); CheckRuleDeletingPermissions(rule); var unitTestId = rule.HttpRequestUnitTestId; repository.Remove(rule); this.SetTempMessage(TempMessageType.Success, "Правило проверки удалёно"); return(RedirectToAction("Edit", new { id = unitTestId })); }
public static MvcHtmlString DeleteConfirmation <T>( this HtmlHelper <T> helper, string actionName, string buttonsSelector) where T : BaseEntityModel { if (string.IsNullOrEmpty(actionName)) { actionName = "Delete"; } var modalId = MvcHtmlString.Create(helper.ViewData.ModelMetadata.ModelType.Name.ToLower() + "-delete-confirmation") .ToHtmlString(); var deleteConfirmationModel = new DeleteConfirmationModel { Id = helper.ViewData.Model.Id, ControllerName = helper.ViewContext.RouteData.GetRequiredString("controller"), ActionName = actionName, WindowId = modalId }; var window = new StringBuilder(); window.AppendLine(string.Format("<div id='{0}' style='display:none;'>", modalId)); window.AppendLine(helper.Partial("Delete", deleteConfirmationModel).ToHtmlString()); window.AppendLine("</div>"); window.AppendLine("<script>"); window.AppendLine("$(document).ready(function() {"); window.AppendLine(string.Format("$('#{0}').click(function (e) ", buttonsSelector)); window.AppendLine("{"); window.AppendLine("e.preventDefault();"); window.AppendLine(string.Format("var window = $('#{0}');", modalId)); window.AppendLine("if (!window.data('kendoWindow')) {"); window.AppendLine("window.kendoWindow({"); window.AppendLine("modal: true,"); window.AppendLine(string.Format("title: '{0}',", "AreYouSure")); window.AppendLine("actions: ['Close']"); window.AppendLine("});"); window.AppendLine("}"); window.AppendLine("window.data('kendoWindow').center().open();"); window.AppendLine("});"); window.AppendLine("});"); window.AppendLine("</script>"); return(MvcHtmlString.Create(window.ToString())); }
public ActionResult Delete(Guid id) { var repository = CurrentAccountDbContext.GetUnitTestTypeRepository(); var unitTestType = repository.GetById(id); CheckDeletingPermissions(unitTestType); var model = new DeleteConfirmationModel() { Id = id.ToString(), Title = "Удаление типа юнит-теста", ModalMode = Request.IsAjaxRequest(), Message = "Вы действительно хотите удалить этот тип проверки?", ReturnUrl = Url.Action("Index") }; return(View("~/Views/Shared/Dialogs/DeleteConfirmation.cshtml", model)); }
public static MvcHtmlString DeleteConfirmation <T>(this HtmlHelper <T> helper, string actionName, string buttonsSelector) where T : BaseNopEntityModel { if (String.IsNullOrEmpty(actionName)) { actionName = "Delete"; } var modalId = MvcHtmlString.Create(helper.ViewData.ModelMetadata.ModelType.Name.ToLower() + "-delete-confirmation").ToHtmlString(); //there's an issue in Telerik (ScriptRegistrar.Current implemenation) //it's a little hack to ensure ScriptRegistrar.Current is loaded helper.Telerik(); #region Write click events for button, if supplied if (!string.IsNullOrEmpty(buttonsSelector)) { var textWriter = new StringWriter(); IClientSideObjectWriter objectWriter = new ClientSideObjectWriterFactory().Create(buttonsSelector, "click", textWriter); objectWriter.Start(); textWriter.Write("function(e){e.preventDefault();openModalWindow(\"" + modalId + "\");}"); objectWriter.Complete(); var value = textWriter.ToString(); ScriptRegistrar.Current.OnDocumentReadyStatements.Add(value); } #endregion var deleteConfirmationModel = new DeleteConfirmationModel { Id = helper.ViewData.Model.Id, ControllerName = helper.ViewContext.RouteData.GetRequiredString("controller"), ActionName = actionName }; var window = helper.Telerik().Window().Name(modalId) .Title(EngineContext.Current.Resolve <ILocalizationService>().GetResource("Admin.Common.AreYouSure")) .Modal(true) .Effects(x => x.Toggle()) .Resizable(x => x.Enabled(false)) .Buttons(x => x.Close()) .Visible(false) .Content(helper.Partial("Delete", deleteConfirmationModel).ToHtmlString()).ToHtmlString(); return(MvcHtmlString.Create(window)); }
public ActionResult DeleteRule(Guid id) { var repository = CurrentAccountDbContext.GetHttpRequestUnitTestRuleRepository(); var rule = repository.GetById(id); CheckRuleDeletingPermissions(rule); var model = new DeleteConfirmationModel() { Id = id.ToString(), Title = "Удаление правила проверки", ModalMode = Request.IsAjaxRequest(), Message = "Вы действительно хотите удалить это правило?", ReturnUrl = Url.Action("Edit", new { id = rule.HttpRequestUnitTestId }) }; return(View("~/Views/Shared/Dialogs/DeleteConfirmation.cshtml", model)); }
public ActionResult Delete(DeleteConfirmationModel model) { if (!ModelState.IsValid) { return(View("~/Views/Shared/Dialogs/DeleteConfirmation.cshtml", model)); } var repository = CurrentAccountDbContext.GetComponentTypeRepository(); var componentType = repository.GetById(Guid.Parse(model.Id)); CheckDeletingPermissions(componentType); var client = GetDispatcherClient(); client.DeleteComponentType(CurrentUser.AccountId, componentType.Id); this.SetTempMessage(TempMessageType.Success, "Тип компонента удалён"); return(Redirect(model.ReturnUrl)); }
public static IHtmlContent DeleteConfirmation <T>(this IHtmlHelper <T> helper, string actionName, string buttonsSelector) where T : BaseYimiEntityModel { if (String.IsNullOrEmpty(actionName)) { actionName = "Delete"; } var modalId = new HtmlString(helper.ViewData.ModelMetadata.ModelType.Name.ToLower() + "-delete-confirmation").ToHtmlString(); var deleteConfirmationModel = new DeleteConfirmationModel { Id = helper.ViewData.Model.Id.ToString(), ControllerName = helper.ViewContext.RouteData.Values["controller"].ToString(), ActionName = actionName, WindowId = modalId }; var window = new StringBuilder(); window.AppendLine(string.Format("<div id='{0}' style='display:none;'>", modalId)); window.AppendLine(helper.Partial("Delete", deleteConfirmationModel).ToHtmlString()); window.AppendLine("</div>"); window.AppendLine("<script>"); window.AppendLine("$(document).ready(function() {"); window.AppendLine(string.Format("$('#{0}').click(function (e) ", buttonsSelector)); window.AppendLine("{"); window.AppendLine("e.preventDefault();"); window.AppendLine(string.Format("var window = $('#{0}');", modalId)); window.AppendLine("if (!window.data('kendoWindow')) {"); window.AppendLine("window.kendoWindow({"); window.AppendLine("modal: true,"); //window.AppendLine(string.Format("title: '{0}',", EngineContext.Current.Resolve<ILocalizationService>().GetResource("Admin.Common.AreYouSure"))); window.AppendLine("actions: ['Close']"); window.AppendLine("});"); window.AppendLine("}"); window.AppendLine("window.data('kendoWindow').center().open();"); window.AppendLine("});"); window.AppendLine("});"); window.AppendLine("</script>"); return(new HtmlString(window.ToString())); }
public ActionResult DeleteContact(DeleteConfirmationModel model) { var repository = CurrentAccountDbContext.GetUserRepository(); var contact = repository.GetContactById(Guid.Parse(model.Id)); if (!CurrentUser.CanManageAccount() && contact.UserId != CurrentUser.Id) { throw new NoAccessToPageException(); } repository.DeleteContactById(contact.Id); if (model.ModalMode) { return(new EmptyResult()); } return(Redirect(model.ReturnUrl)); }
public ActionResult DeleteContact(Guid id) { var repository = CurrentAccountDbContext.GetUserRepository(); var contact = repository.GetContactById(id); if (!CurrentUser.CanManageAccount() && contact.UserId != CurrentUser.Id) { throw new NoAccessToPageException(); } var model = new DeleteConfirmationModel() { Id = id.ToString(), Title = "Удаление контакта", ModalMode = Request.IsAjaxRequest(), Message = "Вы действительно хотите удалить этот контакт?", ReturnUrl = Url.Action("Edit", new { id = contact.UserId }), AjaxUpdateTargetId = "uct_" + id, OnAjaxSuccess = "HideModal" }; return(View("~/Views/Shared/Dialogs/DeleteConfirmation.cshtml", model)); }
public IActionResult RenderDeleteConfirmation(DeleteConfirmationModel model) { return(PartialView("_DeleteConfirmation", model)); }