예제 #1
0
        public async Task <BaseResponse> UpdateTypeArgumentAsync(int typeId, TypeArgumentUpdateViewModel req, string account)
        {
            var data = await _tar.FindAsync(req.Id);

            if (data == null)
            {
                return(new BaseResponse {
                    Success = false, Message = "输入的类型配置数据不存在"
                });
            }
            var arg = await _tar.Find(a => a.TypeId == typeId && a.Name == req.Name).FirstOrDefaultAsync();

            if (arg != null && arg.Id != req.Id)
            {
                return(new BaseResponse {
                    Success = false, Message = "该类型下已存在相同名称的类型配置数据"
                });
            }
            try
            {
                var entity = _mapper.Map(req, data);
                entity.Modify     = account;
                entity.ModifyTime = DateTime.Now;
                await _tar.SaveAsync(entity);

                _log.LogInformation($"{account}修改标示为{req.Id}的类型配置数据成功");
                return(new BaseResponse {
                    Success = true, Message = "修改类型配置数据成功"
                });
            }
            catch (Exception ex)
            {
                _log.LogError($"{account}修改标示为{req.Id}的类型配置数据失败,失败原因:{ex.Message}->{ex.StackTrace}->{ex.InnerException}");
                return(new BaseResponse {
                    Success = false, Message = "修改类型配置数据失败,请联系管理员"
                });
            }
        }
예제 #2
0
        public async Task <ActionResult <BaseResponse> > TypeArgumentUpdate(int typeId, [FromBody] TypeArgumentUpdateViewModel req)
        {
            //string user = User.Identity.Name;
            //if (string.IsNullOrWhiteSpace(user))
            //{
            //    return Unauthorized("用户凭证缺失");
            //}
            //UserMessage um = JsonConvert.DeserializeObject<UserMessage>(user);
            //string GroupId;
            //bool bRet = _ts.IsExist(a => a.Id == typeId, out GroupId);
            //if (!bRet)
            //{
            //    return new BaseResponse { Success = false, Message = "输入的类型不存在" };
            //}
            //if (!(um.IsAdmin && (um.GroupId == GroupId || um.Code == _config["Group"])))
            //{
            //    return Unauthorized("用户没有权限");
            //}
            string Account = User.Claims.FirstOrDefault(a => a.Type == "Account").Value;
            var    rm      = await _tas.UpdateTypeArgumentAsync(typeId, req, Account);

            return(rm);
        }