コード例 #1
0
        /// <summary>
        /// 新增用户定义类型信息
        /// </summary>
        /// <param name="user">创建者</param>
        /// <param name="userTypeValueRequest">请求实体</param>
        /// <param name="cancellationToken">验证</param>
        /// <returns></returns>
        public virtual async Task <UserTypeValueResponse> CreateAsync(UserInfo user, UserTypeValueRequest userTypeValueRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (userTypeValueRequest == null)
            {
                throw new ArgumentNullException(nameof(userTypeValueRequest));
            }
            var buildingno = _mapper.Map <UserTypeValue>(userTypeValueRequest);

            buildingno.Id     = Guid.NewGuid().ToString();
            buildingno.UserId = user.Id;
            try
            {
                await _iuserTypeValueStore.CreateAsync(buildingno, cancellationToken);
            }
            catch
            {
            }
            return(_mapper.Map <UserTypeValueResponse>(buildingno));
        }
コード例 #2
0
        /// <summary>
        /// 修改单个用户定义类型信息
        /// </summary>
        /// <param name="user">请求者</param>
        /// <param name="userTypeValueRequest">请求数据</param>
        /// <param name="cancellationToken">验证</param>
        /// <returns></returns>
        public virtual async Task UpdateAsync(UserInfo user, UserTypeValueRequest userTypeValueRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (userTypeValueRequest == null)
            {
                throw new ArgumentNullException(nameof(userTypeValueRequest));
            }

            var userTypeValue = await _iuserTypeValueStore.GetAsync(a => a.Where(b => b.UserId == user.Id && b.Type == userTypeValueRequest.Type));

            if (userTypeValue == null)
            {
                return;
            }
            userTypeValue.Value = userTypeValueRequest.Value;
            try
            {
                await _iuserTypeValueStore.UpdateAsync(userTypeValue, cancellationToken);
            }
            catch { }
        }
コード例 #3
0
        public async Task <ResponseMessage> PutUserTypeValue(UserInfo user, [FromBody] UserTypeValueRequest userTypeValueRequest)
        {
            var response = new ResponseMessage();

            if (!ModelState.IsValid)
            {
                var error  = "";
                var errors = ModelState.Values.ToList();
                foreach (var item in errors)
                {
                    foreach (var e in item.Errors)
                    {
                        error += e.ErrorMessage + "  ";
                    }
                }
                response.Code    = ResponseCodeDefines.ModelStateInvalid;
                response.Message = error;
                Logger.Warn($"用户{user?.UserName ?? ""}({user?.Id ?? ""})修改用户自定义数据信息(PutUserTypeValue)模型验证失败:\r\n{response.Message ?? ""},\r\n" + (userTypeValueRequest != null ? JsonHelper.ToJson(userTypeValueRequest) : ""));
                return(response);
            }
            try
            {
                var dictionaryGroup = await _userTypeValueManager.FindByUserIdAndTypeAsync(user.Id, userTypeValueRequest.Type, HttpContext.RequestAborted);

                if (dictionaryGroup == null)
                {
                    await _userTypeValueManager.CreateAsync(user, userTypeValueRequest, HttpContext.RequestAborted);
                }
                await _userTypeValueManager.UpdateAsync(user, userTypeValueRequest, HttpContext.RequestAborted);

                response.Code    = ResponseCodeDefines.SuccessCode;
                response.Message = "修改成功";
            }
            catch (Exception e)
            {
                response.Code    = ResponseCodeDefines.ServiceError;
                response.Message = e.ToString();
                Logger.Error($"用户{user?.UserName ?? ""}({user?.Id ?? ""})修改用户自定义数据信息(PutUserTypeValue)请求失败:\r\n{response.Message ?? ""},\r\n" + (userTypeValueRequest != null ? JsonHelper.ToJson(userTypeValueRequest) : ""));
            }
            return(response);
        }