Ejemplo n.º 1
0
        public async Task <ApiResult <string> > Post(EditSysModuleDto Params)
        {
            ApiResult <string> res   = new ApiResult <string>();
            TokenModelBeta     token = JwtToken.ParsingJwtToken(HttpContext);

            try {
                //添加模块
                SysModule sysModuleInfo = _mapper.Map <SysModule>(Params);
                sysModuleInfo.CreatorTime   = DateTime.Now;
                sysModuleInfo.CreatorUserId = token.Id;
                sysModuleInfo.Id            = Guid.NewGuid().ToString();
                sysModuleInfo.DeleteMark    = false;
                var IsSuccess = await _sysModuleService.AddAsync(sysModuleInfo);

                if (!IsSuccess)
                {
                    res.code    = (int)ApiEnum.Failure;
                    res.message = "错误:添加模块失败";
                }

                //添加模块请求
                List <SysModuleAction> AddsysModuleActionList = _mapper.Map <List <SysModuleAction> >(Params.SysModuleActionDtos.Where(s => s.Id == null));
                if (AddsysModuleActionList.Count() > 0)
                {
                    foreach (var item in AddsysModuleActionList)
                    {
                        item.Id            = Guid.NewGuid().ToString();
                        item.ModuleId      = sysModuleInfo.Id;
                        item.CreatorTime   = DateTime.Now;
                        item.CreatorUserId = token.Id;
                    }
                    IsSuccess = await _sysModuleActionService.AddListAsync(AddsysModuleActionList);

                    if (!IsSuccess)
                    {
                        res.code    = (int)ApiEnum.Failure;
                        res.message = "错误:添加模块失败";
                    }
                }
            } catch (Exception ex) {
                res.code    = (int)ApiEnum.Error;
                res.message = "异常:" + ex.Message;
            }

            return(await Task.Run(() => res));
        }
Ejemplo n.º 2
0
        public async Task <ApiResult <string> > Put(string Id, EditSysModuleDto Params)
        {
            ApiResult <string> res   = new ApiResult <string>();
            TokenModelBeta     token = JwtToken.ParsingJwtToken(HttpContext);

            try
            {
                //添加模块
                SysModule sysModuleInfo = _mapper.Map <SysModule>(Params);
                sysModuleInfo.Id = Id;
                var IsSuccess = await _sysModuleService.UpdateAsync(sysModuleInfo);

                if (!IsSuccess)
                {
                    res.code    = (int)ApiEnum.Failure;
                    res.message = "错误:修改模块失败";
                }

                List <string> ModuleIds = new List <string>();

                //修改模块数据
                List <SysModuleAction> EditsysModuleActionList = _mapper.Map <List <SysModuleAction> >(Params.SysModuleActionDtos.Where(s => s.Id != null));
                if (EditsysModuleActionList.Count() > 0)
                {
                    IsSuccess = await _sysModuleActionService.UpdateListAsync(EditsysModuleActionList);

                    if (!IsSuccess)
                    {
                        res.code    = (int)ApiEnum.Failure;
                        res.message = "错误:修改模块失败";
                    }
                    ModuleIds.AddRange(EditsysModuleActionList.Select(s => s.Id).ToList());
                }


                //添加模块请求
                List <SysModuleAction> AddsysModuleActionList = _mapper.Map <List <SysModuleAction> >(Params.SysModuleActionDtos.Where(s => s.Id == null));
                if (AddsysModuleActionList.Count() > 0)
                {
                    foreach (var item in AddsysModuleActionList)
                    {
                        item.Id            = Guid.NewGuid().ToString();
                        item.ModuleId      = sysModuleInfo.Id;
                        item.CreatorTime   = DateTime.Now;
                        item.CreatorUserId = token.Id;
                    }
                    IsSuccess = await _sysModuleActionService.AddListAsync(AddsysModuleActionList);

                    if (!IsSuccess)
                    {
                        res.code    = (int)ApiEnum.Failure;
                        res.message = "错误:添加模块失败";
                    }
                    ModuleIds.AddRange(AddsysModuleActionList.Select(s => s.Id).ToList());
                }

                //删除不存在的模块请求
                await _sysModuleActionService.DeleteAsync(s => s.ModuleId == sysModuleInfo.Id && !ModuleIds.Contains(s.Id));
            }
            catch (Exception ex) {
                res.code    = (int)ApiEnum.Error;
                res.message = "异常:" + ex.Message;
            }

            return(await Task.Run(() => res));
        }