示例#1
0
        public JsonResult Manage(MenuModel model, GridManagingModel manageModel)
        {
            if (ModelState.IsValid || manageModel.Operation == GridOperationEnums.Del)
            {
                return Json(_menuServices.ManageMenu(manageModel.Operation, model));
            }

            return Json(new ResponseModel
            {
                Success = false,
                Message = GetFirstValidationResults(ModelState).Message
            });
        }
示例#2
0
        /// <summary>
        /// Manage Menu
        /// </summary>
        /// <param name="operation"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel ManageMenu(GridOperationEnums operation, MenuModel model)
        {
            Mapper.CreateMap<MenuModel, Menu>();
            Menu menu;
            ResponseModel response;
            switch (operation)
            {
                case GridOperationEnums.Edit:
                    menu = GetById(model.Id);
                    menu.Name = model.Name;
                    menu.Url = model.Url;
                    var hasUpdatePermission = !(model.Controller == menu.Controller && model.Action == menu.Action);
                    menu.Controller = model.Controller;
                    menu.Action = model.Action;
                    menu.ParentId = model.ParentId;
                    menu.MenuIcon = model.MenuIcon;
                    menu.Visible = model.Visible;
                    menu.RecordActive = model.RecordActive;
                    menu.RecordOrder = model.RecordOrder;
                    menu.ParentId = model.ParentName.ToNullableInt();
                    response = HierarchyUpdate(menu);
                    if (hasUpdatePermission) UpdateMenuPermission(menu);
                    return response.SetMessage(response.Success ?
                        _localizedResourceServices.T("AdminModule:::Menus:::Messages:::UpdateSuccessfully:::Update menu successfully.")
                        : _localizedResourceServices.T("AdminModule:::Menus:::UpdateFailure:::Update menu failed. Please try again later."));

                case GridOperationEnums.Add:
                    menu = Mapper.Map<MenuModel, Menu>(model);
                    menu.ParentId = model.ParentName.ToNullableInt();
                    response = HierarchyInsert(menu);
                    UpdateMenuPermission(menu);
                    return response.SetMessage(response.Success ?
                        _localizedResourceServices.T("AdminModule:::Menus:::Messages:::CreateSuccessfully:::Create menu successfully.")
                        : _localizedResourceServices.T("AdminModule:::Menus:::Messages:::CreateFailure:::Create menu failed. Please try again later."));

                case GridOperationEnums.Del:
                    response = Delete(model.Id);
                    return response.SetMessage(response.Success ?
                        _localizedResourceServices.T("AdminModule:::Menus:::Messages:::DeleteSuccessfully:::Delete menu successfully.")
                        : _localizedResourceServices.T("AdminModule:::Menus:::Messages:::DeleteFailure:::Delete menu failed. Please try again later."));
            }
            return new ResponseModel
            {
                Success = false,
                Message = _localizedResourceServices.T("AdminModule:::Menus:::Messages:::ObjectNotFounded:::Menu is not founded.")
            };
        }