public object Any(GetProductById request) { using (var db = DbFactory.OpenDbConnection()) { return(db.SingleById <Product>(request.Id)); } }
public async Task <IEnumerable <ProductDto> > GetProductById(GetProductById query) { using (var dbConnection = dbConnectionFactory()) { const string sql = "select Id, Title, Price, CategoryName from dbo.GetProducts where Id=@Id"; return(await dbConnection.QueryAsync <ProductDto>(sql, query)); } }
public async Task <ActionResult <ProductViewModel> > Get(int ProductId) { var getProductById = new GetProductById { ProductId = ProductId }; return(await _mediator.Send(getProductById)); }
public ShoppingCart(Dictionary <int, Product> sampleList, Dictionary <int, Store> storeList, Dictionary <int, Shipment> shipmentList, GetStoreById getStoreById, GetProductById getProductById) { StoreList = storeList; SampleList = sampleList; ShipmentList = shipmentList; _getStoreById = getStoreById; _getProductById = getProductById; _getShipmentById = GetShipmentById1; }
public async Task <IActionResult> GetProductByIdAsync(int id) { var command = new GetProductById(id); var product = await _mediator.Send(command); if (product != null) { return(Ok(product)); } else { return(NoContent()); } }
public IActionResult Get(int id) { var product = GetProductById.Handle(id); // This is should use AutoMapper on repository // to transform product variable above to ProductResponse. var response = new ProductResponse() { Id = new Guid(), Name = product.Name, Price = product.Price, CreatedAt = DateTime.Today }; return(Ok(response)); }
private async Task <IResponse> HandleGetProductById(GetProductById m) { this.log.Info($"Incoming request for getting product by id {m.Id}"); Result <ProductDocument>?result = await this.relationalDataStoreActorProvider.ExecuteScalarJsonAs <ProductDocument>( DataStoreStatements.GetProductById, new { m.Id }); return(result switch { IsSome <ProductDocument> scalar => new ProductFound { Id = m.Id, Document = scalar.Value }, IsNone => new ProductNotFound(), _ => new ProductRetrievalFailed() });
public async Task <ProductReadModel?> GetProductByIdAsync(GetProductById query) { const string sql = @"SELECT dbo.Products.Id,Brand,Color,CreateTime,[Description],Discount,Expiration,DiscountPrice,ForBaby,Gender,IsDeleted,[Name],Price,Quantity,ProductType,[Weight],Size,Images.[Url],Images.MainImage,Images.Id AS ImgId,Images.ProductId FROM Products LEFT JOIN Images ON dbo.Products.Id=Images.ProductId WHERE dbo.Products.Id=@id AND IsDeleted=0;"; await using var connection = new SqlConnection(_connectionString); await using var command = new SqlCommand(sql, connection); command.Parameters.Add("@id", SqlDbType.BigInt).Value = query.Id; await connection.EnsureIsOpenAsync().ConfigureAwait(false); await using var reader = await command.ExecuteReaderAsync().ConfigureAwait(false); var product = await ReadProductAsync(reader).ConfigureAwait(false); return(product); }
public async Task <IActionResult> GetProductById([FromRoute] GetProductById query) { var products = await queryService.GetProductById(query); var product = products.FirstOrDefault(); if (product == null) { return(NotFound()); } var result = new GetProductByIdResult { Id = product.Id, Title = product.Title, Price = product.Price, Categories = products .Where(c => c.CategoryName != null) .Select(c => c.CategoryName) .ToArray() }; return(Ok(result)); }
public Task <ProductReadModel> HandleAsync(GetProductById query) { return(_readRepository.GetProductByIdAsync(query)); }
public bool GetProductById(GetProductById product) { throw new NotImplementedException(); }
public async Task <IActionResult> GetProductByIdAsync([FromQuery] GetProductById query) { var data = await Mediator.QueryAsync(query).ConfigureAwait(false); return(Ok(data)); }
public async Task <IActionResult> GetProductById(GetProductById query) { var product = await _queryProcessor.QueryAsync(query); return(Ok(product)); }