public async Task <FuncResult> AddOrUpdateMethod([FromBody] MethodRouteModel model)
 {
     return(await sysRouteBLL.AddOrUpdateMethod(model, CurrentUser.Get().Id));
 }
예제 #2
0
        public async Task <FuncResult> AddOrUpdateMethod(MethodRouteModel model, int currentUserId)
        {
            if (await _context.SysControllerRoutes.FindAsync(model.ControllerId) == null)
            {
                return(new FuncResult()
                {
                    IsSuccess = false, Message = "ControllerId错误!"
                });
            }
            if (string.IsNullOrWhiteSpace(model.MethodType))
            {
                return(new FuncResult()
                {
                    IsSuccess = false, Message = "Method路径不能为空"
                });
            }

            if (!Regex.Match(model.MethodPath, @"^[a-zA-Z0-9]+$").Success)
            {
                return(new FuncResult()
                {
                    IsSuccess = false, Message = "MethodPath只能输入字母、数字"
                });
            }

            if (string.IsNullOrWhiteSpace(model.MethodAlias))
            {
                model.MethodAlias = model.MethodAlias;
            }
            if (string.IsNullOrWhiteSpace(model.MethodType))
            {
                model.MethodType = "HttpGet";
            }
            if (_context.SysMethodRoutes.Where(e => e.ControllerId == model.ControllerId && e.Id != model.Id).Select(e => e.MethodPath.ToLower()).Contains(model.MethodPath))
            {
                return(new FuncResult()
                {
                    IsSuccess = false, Message = "路径重复"
                });
            }
            if (_context.SysMethodRoutes.Where(e => e.ControllerId == model.ControllerId && e.Id != model.Id).Select(e => e.MethodAlias.ToLower()).Contains(model.MethodAlias))
            {
                return(new FuncResult()
                {
                    IsSuccess = false, Message = "别名重复"
                });
            }



            SysMethodRoute entity = new SysMethodRoute();

            if (!string.IsNullOrWhiteSpace(model.Id))
            {
                entity = await _context.SysMethodRoutes.FindAsync(model.Id);

                if (entity == null)
                {
                    return(new FuncResult()
                    {
                        IsSuccess = false, Message = "id错误"
                    });
                }
                entity.MethodAlias  = model.MethodAlias;
                entity.MethodPath   = model.MethodPath;
                entity.ControllerId = model.ControllerId;
                entity.MethodType   = model.MethodType;


                entity.Last_Updated_By  = currentUserId;
                entity.Last_Update_Date = DateTime.Now;
                _context.SysMethodRoutes.Update(entity);
                await _context.SaveChangesAsync();

                return(new FuncResult()
                {
                    IsSuccess = true, Content = entity, Message = "编辑成功"
                });
            }

            entity.Id           = Guid.NewGuid().ToString("N");
            entity.MethodAlias  = model.MethodAlias;
            entity.MethodPath   = model.MethodPath;
            entity.ControllerId = model.ControllerId;
            entity.MethodType   = model.MethodType;

            entity.Last_Updated_By  = currentUserId;
            entity.Last_Update_Date = DateTime.Now;
            entity.Created_By       = currentUserId;
            entity.Creation_Date    = DateTime.Now;

            await _context.SysMethodRoutes.AddAsync(entity);

            await _context.SaveChangesAsync();

            return(new FuncResult()
            {
                IsSuccess = true, Content = entity, Message = "添加成功"
            });
        }
예제 #3
0
 public async Task <FuncResult> AddOrUpdateMethod([FromBody] MethodRouteModel model)
 {
     return(await sysRouteBLL.AddOrUpdateMethod(model, HttpContext.CurrentUser(cache).Id));
 }