Ejemplo n.º 1
0
        public virtual async Task UpdateAsync(string groupId, string value, DictionaryDefineUpdateRequest dictionaryDefineUpdateRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (dictionaryDefineUpdateRequest == null || string.IsNullOrEmpty(groupId) || string.IsNullOrEmpty(value))
            {
                throw new ArgumentNullException(nameof(dictionaryDefineUpdateRequest));
            }
            var dicdefine = await Store.GetAsync(a => a.Where(b => b.GroupId == groupId && b.Value == value));

            if (dicdefine == null)
            {
                throw new Exception("未找到更新对象");
            }
            dicdefine.Ext1  = dictionaryDefineUpdateRequest.Ext1;
            dicdefine.Ext2  = dictionaryDefineUpdateRequest.Ext2;
            dicdefine.Key   = dictionaryDefineUpdateRequest.Key;
            dicdefine.Order = dictionaryDefineUpdateRequest.Order;

            await Store.UpdateAsync(dicdefine, cancellationToken);
        }
        public async Task <ResponseMessage> PutDictionaryGroup(UserInfo user, [FromRoute] string groupId, [FromRoute] string value, [FromBody] DictionaryDefineUpdateRequest dictionaryDefineUpdateRequest)
        {
            ResponseMessage response = new ResponseMessage();

            if (!ModelState.IsValid)
            {
                response.Code    = ResponseCodeDefines.ModelStateInvalid;
                response.Message = ModelState.GetAllErrors();
                Logger.Warn($"用户{user?.UserName ?? ""}({user?.Id ?? ""})修改字典数据(PutDictionaryGroup)模型验证失败:\r\n{response.Message ?? ""},\r\n" + (dictionaryDefineUpdateRequest != null ? JsonHelper.ToJson(dictionaryDefineUpdateRequest) : ""));
                return(response);
            }
            try
            {
                await _dictionaryDefineManager.UpdateAsync(groupId, value, dictionaryDefineUpdateRequest, HttpContext.RequestAborted);
            }
            catch (Exception e)
            {
                response.Code    = ResponseCodeDefines.ServiceError;
                response.Message = e.ToString();
                Logger.Error($"用户{user?.UserName ?? ""}({user?.Id ?? ""})修改字典数据(PutDictionaryGroup)请求失败:\r\n{response.Message ?? ""},\r\n" + (dictionaryDefineUpdateRequest != null ? JsonHelper.ToJson(dictionaryDefineUpdateRequest) : ""));
            }
            return(response);
        }