Пример #1
0
        public IActionResult DeleteMenuItem(int menuItemId)
        {
            var menuItem = menuItemId > 0 ? _menuItemService.Get(menuItemId) : null;

            if (menuItem == null)
            {
                return(NotFound());
            }
            //get the menu to get the entire tree
            var menu = _menuService.Get(menuItem.MenuId);

            if (menu == null)
            {
                return(NotFound());
            }
            Transaction.Initiate(transaction =>
            {
                _menuItemService.Delete(menuItem, transaction);
                //get all the children
                var childMenuItems = menu.MenuItems.First(x => x.Id == menuItemId).Children.SelectManyRecursive(x => x.Children);
                foreach (var cm in childMenuItems)
                {
                    _menuItemService.Delete(cm, transaction);
                }
            });

            return(R.Success.Result);
        }
Пример #2
0
        public ActionResult SaveData(MenuItemChangeViewModel menuitems)
        {
            if (menuitems.updated != null)
            {
                foreach (var updated in menuitems.updated)
                {
                    _menuItemService.Update(updated);
                }
            }
            if (menuitems.deleted != null)
            {
                foreach (var deleted in menuitems.deleted)
                {
                    _menuItemService.Delete(deleted);
                }
            }
            if (menuitems.inserted != null)
            {
                foreach (var inserted in menuitems.inserted)
                {
                    _menuItemService.Insert(inserted);
                }
            }
            _unitOfWork.SaveChanges();

            return(Json(new { Success = true }, JsonRequestBehavior.AllowGet));
        }
Пример #3
0
        public async Task <JsonResult> SaveDataAsync(MenuItemChangeViewModel menuitems)
        {
            if (menuitems == null)
            {
                throw new ArgumentNullException(nameof(menuitems));
            }
            if (ModelState.IsValid)
            {
                if (menuitems.updated != null)
                {
                    foreach (var item in menuitems.updated)
                    {
                        menuItemService.Update(item);
                    }
                }
                if (menuitems.deleted != null)
                {
                    foreach (var item in menuitems.deleted)
                    {
                        menuItemService.Delete(item);
                    }
                }
                if (menuitems.inserted != null)
                {
                    foreach (var item in menuitems.inserted)
                    {
                        menuItemService.Insert(item);
                    }
                }
                try
                {
                    var result = await unitOfWork.SaveChangesAsync();

                    return(Json(new { success = true, result = result }, JsonRequestBehavior.AllowGet));
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException e)
                {
                    var errormessage = string.Join(",", e.EntityValidationErrors.Select(x => x.ValidationErrors.FirstOrDefault()?.PropertyName + ":" + x.ValidationErrors.FirstOrDefault()?.ErrorMessage));
                    return(Json(new { success = false, err = errormessage }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception e)
                {
                    return(Json(new { success = false, err = e.GetBaseException().Message }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                var modelStateErrors = string.Join(",", ModelState.Keys.SelectMany(key => ModelState[key].Errors.Select(n => n.ErrorMessage)));
                return(Json(new { success = false, err = modelStateErrors }, JsonRequestBehavior.AllowGet));
            }
        }
Пример #4
0
        public IActionResult OnGetDeleteMenuItem(int itemId)
        {
            var the_item = _menuService.GetById(itemId);

            _menuService.Delete(the_item);
            return(RedirectToPage("MenuItemList"));
        }
Пример #5
0
        public IActionResult DeleteConfirmed(int id)
        {
            MenuItem menuItem = _menuItemService.GetById(id);

            _menuItemService.Delete(menuItem);
            _menuItemService.Commit();
            return(RedirectToAction("Index"));
        }
Пример #6
0
        public ActionResult DeleteItem(int id)
        {
            if (!CheckPermission(MenusPermissions.ManageMenus))
            {
                return(new HttpUnauthorizedResult());
            }

            var menuItem = menuItemService.GetById(id);

            menuItemService.Delete(menuItem);
            return(new AjaxResult().NotifyMessage("DELETE_MENUITEM_COMPLETE"));
        }
        //[ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            MenuItem menuItem = _menuItemService.Find(id);

            _menuItemService.Delete(menuItem);
            _unitOfWork.SaveChanges();
            if (Request.IsAjaxRequest())
            {
                return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
            }
            DisplaySuccessMessage("Has delete a MenuItem record");
            return(RedirectToAction("Index"));
        }
Пример #8
0
        public ActionResult Delete(int menuItemId)
        {
            _menuItemService.Delete(menuItemId);

            return(Redirect(HttpContext.Request.UrlReferrer.ToString()));
        }
 public IActionResult Delete([FromRoute] int id)
 {
     _menuItemService.Delete(id);
     return(Ok());
 }
Пример #10
0
        public ActionResult SaveAndContinue(PageModel model)
        {
            if (!CheckPermission(PagesPermissions.ManagePages))
            {
                return(new HttpUnauthorizedResult());
            }

            Page page = new Page();

            if (model.Id != 0)
            {
                page = pageService.GetById(model.Id);
                var historicPage = new HistoricPage
                {
                    ArchivedDate    = DateTime.UtcNow,
                    BodyContent     = page.BodyContent,
                    CssClass        = page.CssClass,
                    CultureCode     = page.CultureCode,
                    IsEnabled       = page.IsEnabled,
                    MetaDescription = page.MetaDescription,
                    MetaKeywords    = page.MetaKeywords,
                    PageId          = page.Id,
                    RefId           = page.RefId,
                    Slug            = page.Slug,
                    Theme           = page.Theme,
                    Title           = page.Title
                };
                historicPageService.Insert(historicPage);
            }

            page.Title           = model.Title;
            page.IsEnabled       = model.IsEnabled;
            page.MetaKeywords    = model.MetaKeywords;
            page.MetaDescription = model.MetaDescription;
            page.BodyContent     = model.BodyContent;
            page.CultureCode     = model.CultureCode;
            page.RefId           = model.RefId;
            page.Theme           = model.Theme;
            page.CssClass        = model.CssClass;
            page.Slug            = string.IsNullOrEmpty(model.Slug) ? model.Title.ToSlugUrl() : model.Slug.Trim(' ', '/');

            pageService.Save(page);

            if (page.RefId == null)
            {
                if (model.ShowOnMenuId == null)
                {
                    if (model.Id != 0)
                    {
                        var menuItem = menuItemService.GetMenuItemByRefId(model.Id);
                        if (menuItem != null)
                        {
                            menuItemService.Delete(menuItem);
                        }
                    }
                }
                else
                {
                    var menuItem = menuItemService.GetMenuItemByRefId(model.Id) ?? new MenuItem
                    {
                        RefId         = page.Id,
                        Position      = 0,
                        Enabled       = true,
                        IsExternalUrl = false,
                        Text          = page.Title
                    };
                    menuItem.Url    = page.Slug;
                    menuItem.MenuId = model.ShowOnMenuId.Value;
                    menuItemService.Save(menuItem);
                }
            }

            return(null);
        }
Пример #11
0
        public ActionResult Delete(int menuItemId)
        {
            _menuItemService.Delete(menuItemId);

            return(RedirectToAction("Index", "SettingManager"));
        }