public override async Task <PurchaseResponse> AddPurchase(PurchaseRequest request, ServerCallContext context) { if (!Guid.TryParse(request.Purchase.ProductId, out Guid productID)) { throw new ArgumentException($"invalid product id {request.Purchase.ProductId}"); } if (!Guid.TryParse(request.Purchase.TransactionId, out Guid transactionID)) { throw new ArgumentException($"invalid transaction id {request.Purchase.TransactionId}"); } var purchase = new Shared.DAL.Purchase { ProductID = productID, TransactionID = transactionID, Count = request.Purchase.Count, Price = request.Purchase.Price, Created = request.Purchase.Created.ToDateTime() }; var response = new PurchaseResponse(); var entry = await this.repo.AddPurchaseAsync(purchase); response.Purchases.Add(new Purchase { ProductId = entry.ProductID.ToString(), TransactionId = entry.TransactionID.ToString(), Count = entry.Count, Price = Convert.ToInt32(entry.Price), Created = Timestamp.FromDateTime(entry.Created) }); return(response); }
public async Task <ProductResponse> GetProductsAsync(Shared.DAL.Purchase purchase) => await Client.GetProductAsync(new ProductRequest { Purchase = new Purchase { ProductId = purchase.ProductID.ToString(), TransactionId = purchase.TransactionID.ToString() } });
public async Task <PurchaseResponse> AddPurchaseAsync(Shared.DAL.Purchase purchase) => await Client.AddPurchaseAsync(new PurchaseRequest { Purchase = new Purchase { ProductId = purchase.ProductID.ToString(), TransactionId = purchase.TransactionID.ToString(), Price = Convert.ToInt32(purchase.Price), Count = purchase.Count } });