コード例 #1
0
        public async Task <ResponseMessage> PutShops(UserInfo user, [FromRoute] string shopsId, [FromBody] ShopsRequest shopsRequest)
        {
            Logger.Trace($"用户{user?.UserName ?? ""}({user?.Id ?? ""})修改商铺信息(PutShops):\r\n请求参数为:\r\n(shopsId){shopsId ?? ""}\r\n" + (shopsRequest != null ? JsonHelper.ToJson(shopsRequest) : ""));

            ResponseMessage response = new ResponseMessage();

            if (!ModelState.IsValid || shopsRequest.Id != shopsId)
            {
                response.Code = ResponseCodeDefines.ModelStateInvalid;
                Logger.Warn($"用户{user?.UserName ?? ""}({user?.Id ?? ""})修改商铺信息(PutShops)模型验证失败:\r\n{response.Message ?? ""},\r\n请求参数为:\r\n(shopsId){shopsId ?? ""}\r\n" + (shopsRequest != null ? JsonHelper.ToJson(shopsRequest) : ""));
                return(response);
            }
            try
            {
                var dictionaryGroup = await _shopsManager.FindByIdAsync(user.Id, shopsId, HttpContext.RequestAborted);

                if (dictionaryGroup == null)
                {
                    await _shopsManager.CreateAsync(user, shopsRequest, HttpContext.RequestAborted);
                }
                await _shopsManager.UpdateAsync(user.Id, shopsId, shopsRequest, HttpContext.RequestAborted);
            }
            catch (Exception e)
            {
                response.Code    = ResponseCodeDefines.ServiceError;
                response.Message = e.ToString();
                Logger.Error($"用户{user?.UserName ?? ""}({user?.Id ?? ""})修改商铺信息(PutShops)请求失败:\r\n{e.ToString()},\r\n请求参数为:\r\n(shopsId){shopsId ?? ""}\r\n" + (shopsRequest != null ? JsonHelper.ToJson(shopsRequest) : ""));
            }
            return(response);
        }