Example #1
0
        public async Task <ResponseMessage> PutBuildingNotice(UserInfo user, [FromRoute] string noticeId, [FromBody] BuildingNoticeRequest buildingNoticeRequest)
        {
            Logger.Trace($"用户{user?.UserName ?? ""}({user?.Id ?? ""})更新一条跑马灯(PutBuildingNotice):\r\n请求参数为:\r\n" + (buildingNoticeRequest != null ? JsonHelper.ToJson(buildingNoticeRequest) : ""));

            ResponseMessage response = new ResponseMessage();

            if (!ModelState.IsValid)
            {
                response.Code    = ResponseCodeDefines.ModelStateInvalid;
                response.Message = ModelState.GetAllErrors();
                Logger.Warn($"用户{user?.UserName ?? ""}({user?.Id ?? ""})更新一条跑马灯(PutBuildingNotice)报错:\r\n{response.Message ?? ""},\r\n请求参数为:\r\n" + (buildingNoticeRequest != null ? JsonHelper.ToJson(buildingNoticeRequest) : ""));
                return(response);
            }
            try
            {
                await _buildingNoticeManager.UpdateAsync(noticeId, buildingNoticeRequest, HttpContext.RequestAborted);
            }
            catch (Exception e)
            {
                response.Code    = ResponseCodeDefines.ServiceError;
                response.Message = e.ToString();
                Logger.Error($"用户{user?.UserName ?? ""}({user?.Id ?? ""})更新一条跑马灯(PutBuildingNotice)报错:\r\n{e.ToString()},\r\n请求参数为:\r\n" + (buildingNoticeRequest != null ? JsonHelper.ToJson(buildingNoticeRequest) : ""));
            }
            return(response);
        }
        public async Task <ResponseMessage> UploadIcon(UserInfo user, [FromBody] string iconPath, [FromRoute] string dest, [FromRoute] string buildingId)
        {
            ResponseMessage response = new ResponseMessage();

            if (string.IsNullOrEmpty(iconPath) || string.IsNullOrEmpty(dest) || string.IsNullOrEmpty(buildingId))
            {
                response.Code    = ResponseCodeDefines.ArgumentNullError;
                response.Message = "参数不能为空";
                Logger.Error($"用户{user?.UserName ?? ""}({user?.Id ?? ""})更新缩略图(UploadIcon)参数验证错误:参数不能为空,请求参数为:\r\n(iconPath){iconPath ?? ""},(dest){dest ?? ""},(buildingId){buildingId ?? ""}");
                return(response);
            }
            try
            {
                if (dest == "building")
                {
                    var building = await _buildingsManager.FindByIdAsync(user.Id, buildingId);

                    if (building != null)
                    {
                        building.Icon = iconPath;
                        await _buildingsManager.UpdateAsync(user.Id, buildingId, _mapper.Map <BuildingRequest>(building));
                    }
                }
                else if (dest == "shops")
                {
                    var shops = await _shopsManager.FindByIdAsync(user.Id, buildingId);

                    if (shops != null)
                    {
                        shops.Icon = iconPath;
                        await _shopsManager.UpdateAsync(user.Id, buildingId, _mapper.Map <ShopsRequest>(shops));
                    }
                }
                else if (dest == "updaterecord")
                {
                    var records = await _updateRecordManager.FindByIdAsync(buildingId);

                    if (records != null)
                    {
                        records.Icon = iconPath;
                        await _shopsManager.UpdateAsync(user.Id, buildingId, _mapper.Map <ShopsRequest>(records));
                    }
                }
                else if (dest == "buildingnotice")
                {
                    var notice = await _buildingNoticeManager.FindByIdAsync(buildingId);

                    if (notice != null)
                    {
                        notice.Icon = iconPath;
                        await _buildingNoticeManager.UpdateAsync(buildingId, _mapper.Map <BuildingNoticeRequest>(notice));
                    }
                }
            }
            catch (Exception e)
            {
                response.Code    = ResponseCodeDefines.ServiceError;
                response.Message = e.ToString();
                Logger.Error($"用户{user?.UserName ?? ""}({user?.Id ?? ""})更新缩略图(UploadIcon)报错:\r\n{e.ToString()},请求参数为:\r\n(iconPath){iconPath ?? ""},(dest){dest ?? ""},(buildingId){buildingId ?? ""}");
            }
            return(response);
        }