public void Insert(ProductReadModel product) { _sqlConnection.Execute( @"INSERT INTO ProductReadModels (Id, Name, CategoryId, OrderAmount, Review, FieldValues) VALUES(@Id, @Name, @CategoryId, @OrderAmount @Review, @FieldValues)", product); }
public IActionResult Put(int id, [FromBody] ProductReadModel product) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } return(Ok()); }
public void Update(ProductReadModel product) { _sqlConnection.Execute( @"UPDATE ProductReadModels (Name, CategoryId, OrderAmount, Review, FieldValues) VALUES(@Name, @CategoryId, @OrderAmount @Review, @FieldValues) WHERE Id = @Id", product); }
public Task AddProductAsync(ProductReadModel product, CancellationToken cancellationToken = default(CancellationToken)) { if (product == null) { throw new System.ArgumentNullException(nameof(product)); } _products.Add(product); return(Task.CompletedTask); }
public static ProductModel FromReadModel(ProductReadModel p) { return(new ProductModel { Id = p.Id, Name = p.Name, Price = p.Price, Quantity = p.Quantity }); }
public Task UpdateProductAsync(ProductReadModel updatedProduct, CancellationToken cancellationToken = default(CancellationToken)) { if (updatedProduct == null) { throw new System.ArgumentNullException(nameof(updatedProduct)); } DeleteProductByIdAsync(updatedProduct.ProductId); AddProductAsync(updatedProduct); return(Task.CompletedTask); }
public async Task <IActionResult> GetProduct(Guid productId) { ProductReadModel product = await _queryDispatcher.DispatchAsync <QueryProductById, ProductReadModel>(new QueryProductById(productId)); if (product != null) { return(Ok(product)); } return(NotFound()); }
public async Task HandleAsync(CreatedProductEvent @event, CancellationToken cancellationToken = new CancellationToken()) { var productReadModel = new ProductReadModel() { Id = @event.AggregateId, Name = @event.Name, }; IsHandled = true; await _repo.WriteAsync(productReadModel); }
public async Task <IActionResult> GetProduct(int productId) { // Get from read side. ProductReadModel product = await _productRepository.GetProductByIdAsync(productId); if (product != null) { return(Ok(product)); } return(NotFound()); }
public async Task <IActionResult> Post([FromBody] ProductReadModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var product = _mapper.Map <Product>(model); product = await _mediator.Send(new SaveProductRequest(product)); return(Ok(product)); }
public int Put(ProductReadModel product) { InitClientId(); var carts = App.Read <BasketRequest, BasketsReadModel>(new BasketRequest()); App.Send(new AddProductToCart { ProductId = product.ProductId, Quantity = 1, CartId = carts.GetCart(ClientId).CartId }); return(carts.GetCart(ClientId).Items.FirstOrDefault(item => item.ProductId == product.ProductId)?.Quantity ?? 0); }
public void Create_product_aggregate_should_flow() { // Given var aggregate = Fixture.Create <Product>(); // When _sut = ProductReadModel.Create(aggregate); // Then _sut.Id.Should().Be(aggregate.Id); _sut.Name.Should().Be(aggregate.Name); _sut.Value.Should().Be(aggregate.Value); _sut.Image.Should().Be(aggregate.Image); }
public override async Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) { int productId = RequestInput <int>("Enter ID of product to display:", input => { if (int.TryParse(input, out int i)) { return(InputValidationResult.Success); } return(InputValidationResult.WithErrors("Invalid product ID.")); }); ProductReadModel product = await _productReadSideRepository.GetProductByIdAsync(productId); if (product == null) { Console.WriteLine("Product not found."); return; } Console.WriteLine($"Product ID: {product.ProductId}, Product Name: {product.ProductName}, IsActive: {product.IsActive}"); }
public void Handle(ProductAddedEvent @event, DatabaseContext db) { try { var product = @event.Product; var categoryIds = !string.IsNullOrWhiteSpace(product.CategoryIds) ? product.CategoryIds.Split(',') .Select(Int32.Parse) .ToList() : new List <int>(); var categories = db.Set <Category>() .Where(category => categoryIds.Contains(category.Id)) .Distinct() .ToList(); var productDetails = new ProductReadModel() { AggregateRootId = product.Id, Name = product.Name, CreatedDate = product.CreateDate.UtcDateTime, Code = product.Code, Amount = product.Amount, PhotoHeight = product.Photo.Height, PhotoUrl = product.Photo.Url, PhotoWidth = product.Photo.Width, CategoryIds = product.CategoryIds, CategoryNames = categories?.Any() == true?string.Join(',', categories.Select(category => category.Name).ToList()) : string.Empty }; db.Set <ProductReadModel>().Add(productDetails); @event.Message = "Product Succesfully placed..."; } catch (Exception exc) { throw; } }
public override async Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) { string productId = RequestInput("Enter ID of product to display:", input => { if (Guid.TryParse(input, out Guid i)) { return(InputValidationResult.Success); } return(InputValidationResult.WithErrors("Invalid product ID.")); }); ProductReadModel product = await _queryDispatcher.DispatchAsync <QueryProductById, ProductReadModel>(new QueryProductById(Guid.Parse(productId))); if (product != null) { System.Console.WriteLine($"Product ID: {product.ProductId}, Product Name: {product.ProductName}, IsActive: {product.IsActive}"); } else { System.Console.WriteLine($"Product with ID {productId} was not found."); } }
public void Handle(ProductPlacedEvent @event, DatabaseContext db) { var product = @event.Product; if (product == null) { return; } var productReadModel = new ProductReadModel(product.Code, product.Id, product.BoothIds, product.Name, product.Description, product.Price, product.ProductSupplierId, product.ProductSupplier.Name, product.Photo.Url, product.Photo.Width, product.Photo.Height); db.Set <ProductReadModel>() .Add(productReadModel); }
public async Task HandleAsync(CreatedProductEvent @event, CancellationToken cancellationToken = default) { var productModel = new ProductReadModel() { Id = @event.AggregateId, Version = @event.Version, Price = @event.Price, Color = @event.Color, Brand = @event.Brand, ProductType = @event.ProductType, Weight = @event.Weight, Name = @event.Name, Description = @event.Description, Gender = @event.Gender, ForBaby = @event.ForBaby, Size = @event.Size, Discount = @event.Discount, CreateTime = @event.CreateTime, Expiration = @event.Expiration, Images = @event.Images, }; await _repo.WriteAsync(productModel, cancellationToken); }
public void Delete(ProductReadModel product) { // Nope, hasn't been implemented }
private static void PrintProducts(ProductReadModel product) { System.Console.WriteLine($"ProductID: {product.ProductId} | Description: { product.Description } | Price: {product.Price}"); }
public void Put(ProductReadModel product) { App.Send(new UpdateProduct { ProductId = product.ProductId, Description = product.Description, Price = product.Price }); }
public void Handle(ProductAddedEvent @event) { var product = new ProductReadModel(@event); _repo.Insert(product); }