public static GetAuctionResponse Translate(Auction entity) => entity != null?GetAuctionResponse.Create( id : entity.Id, userId : entity.UserId, name : entity.Name, initialValue : entity.InitialValue, used : entity.Used, startDate : entity.StartDate, endDate : entity.EndDate, user : GetUserResponse.Create(id: entity.UserReference.Id, username: entity.UserReference.Username, role: entity.UserReference.Role) ) : GetAuctionResponse.Create();
public override async Task <GetAuctionResponse> GetAuction(GetAuctionRequest request, ServerCallContext context) { Models.Auction auction; if (request.AuctionId == "active") { auction = await _auctionService.GetActiveAuction(); if (auction == null) { throw new RpcException(new Status(StatusCode.NotFound, "no active auction running")); } } else { Guid auctionId; if (!Guid.TryParse(request.AuctionId, out auctionId)) { throw new RpcException(new Status(StatusCode.InvalidArgument, "entryid is not a guid")); } auction = _auctionService.GetAuction(auctionId); } if (auction == null) { throw new RpcException(new Status(StatusCode.NotFound, "auction not found")); } var res = new GetAuctionResponse { Auction = new Auction { Id = auction.Id.ToString(), StartedAt = auction.StartedAt, Duration = auction.Duration, FinishedAt = auction.FinishedAt, } }; return(res); }