Пример #1
0
        public async Task <ResponseMessage <UpdateRecordResponse> > GetUpdateRecord(UserInfo user, [FromRoute] string updateId)
        {
            ResponseMessage <UpdateRecordResponse> response = new ResponseMessage <UpdateRecordResponse>();

            if (string.IsNullOrEmpty(updateId))
            {
                response.Code    = ResponseCodeDefines.ModelStateInvalid;
                response.Message = "参数不能为空";
                Logger.Warn($"用户{user?.UserName ?? ""}({user?.Id ?? ""})获取房源动态(GetUpdateRecord)报错:参数不能为空,\r\n请求参数为:\r\n(updateId){updateId ?? ""}");
            }
            try
            {
                response.Extension = await _updateRecordManager.FindByIdAsync(updateId, HttpContext.RequestAborted);
            }
            catch (Exception e)
            {
                response.Code    = ResponseCodeDefines.ServiceError;
                response.Message = e.ToString();
                Logger.Error($"用户{user?.UserName ?? ""}({user?.Id ?? ""})获取房源动态(GetUpdateRecord)报错:\r\n{e.ToString()},\r\n请求参数为:\r\n(updateId){updateId ?? ""}");
            }
            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);
        }