Esempio n. 1
0
        public async Task <bool> Add(AddMenuRequestModel model)
        {
            try
            {
                if (!model.IsNull())
                {
                    using (var uow = _unitOfWorkFactory.CreateUow())
                    {
                        uow.GetEntityRepository <Menu>().Insert(new Menu
                        {
                            Id          = Guid.NewGuid().ToString(),
                            Name        = model.Name,
                            Description = model.Description,
                            DateCreated = DateTime.Now.GetDate(),
                        });

                        await uow.Commit();

                        return(true);
                    }
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);
                _logger.LogTrace(e.StackTrace);
            }
            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// 新增菜单
        /// </summary>
        /// <param name="requestModel">参数</param>
        /// <returns></returns>
        public ApiResultModel <int> Add(AddMenuRequestModel requestModel)
        {
            var result = new ApiResultModel <int>();

            if (requestModel.MenuName.IsNullOrEmpty())
            {
                result.Message = "菜单名称不能为空";
                return(result);
            }
            if (requestModel.ParentId.IsNullOrEmpty())
            {
                result.Message = "上级不能为空";
                return(result);
            }
            //if (requestModel.Path.IsNullOrEmpty())
            //{
            //    result.Message = "菜单路径不能为空";
            //    return result;
            //}
            if (requestModel.Type == MenuTypeEnum.Module || requestModel.Type == MenuTypeEnum.Function)
            {
                var menu = _menuRepository.FirstOrDefault(x => x.name == requestModel.MenuName && x.type == (int)requestModel.Type);
                if (menu != null)
                {
                    result.Message = "此菜单名已存在";
                    return(result);
                }
            }
            var item = new Menu()
            {
                id       = GuidTool.GetGuid(),
                name     = requestModel.MenuName,
                parentId = requestModel.ParentId,
                type     = (int)requestModel.Type,
                sort     = requestModel.Sort,
                path     = requestModel.Path ?? "",
                icon     = requestModel.Icon ?? "",
            };

            _menuRepository.Add(item);
            //_menuRepository.Entry(item).State = EntityState.Added;
            _menuRepository.SaveChanges();

            result.Code = ApiResultCode.Success;
            return(result);
        }
Esempio n. 3
0
        public ActionResult AddAjax(AddMenuRequestModel requestModel)
        {
            var res = _menuService.Add(requestModel);

            return(Content(res.ToJsonString()));
        }