protected override async Task HandleCore(Command message) { var uploadPath = Path.Combine(_environment.WebRootPath, "images/products"); var ImageName = ContentDispositionHeaderValue.Parse(message.ImageUpload.ContentDisposition).FileName.Trim('"'); using (var fileStream = new FileStream(Path.Combine(uploadPath, message.ImageUpload.FileName), FileMode.Create)) { await message.ImageUpload.CopyToAsync(fileStream); message.ImageUrl = "http://catalogbaseurl/images/products/" + ImageName; } var item = CatalogItem.Create( message.TypeId, message.BrandId, message.Stock, message.Price, message.Name, message.Description, ImageName, message.ImageUrl ); _context.CatalogItems.Add(item); await _context.SaveChangesAsync(); }
public void CanAddItemToCart() { var cart = Cart.Create(GivenUser()); var catalogItem = CatalogItem.Create( sku: "CAFE-314", description: "1 Pound Guatemalan Coffee Beans", unitPrice: 18.80m); cart.AddItem(catalogItem, 2); cart.CartItems.Count().Should().Be(1); }
protected CartServiceContext() { Context.Add(CatalogItem.Create ( sku: "CAFE-314", description: "1 Pound Guatemalan Coffee Beans", unitPrice: 18.80m )); CartService = new CartService(Repository, new MockLog()); User = WhenCreateUser(); }
public void GroupItemsOfSameKind() { var cart = Cart.Create(GivenUser()); var catalogItem = CatalogItem.Create( sku: "CAFE-314", description: "1 Pound Guatemalan Coffee Beans", unitPrice: 18.80m); cart.AddItem(catalogItem, 2); cart.AddItem(catalogItem, 1); cart.CartItems.Count().Should().Be(1); cart.CartItems.Single().Quantity.Should().Be(3); }
private void InitializeCartWithOneItem(InMemoryDataContext context) { var user = context.Add(User.Create("*****@*****.**")); context.Commit(); var cart = context.Add(Cart.Create(user)); var catalogItem = context.Add(CatalogItem.Create ( sku: "CAFE-314", description: "1 Pound Guatemalan Coffee Beans", unitPrice: 18.80m )); cart.AddItem(catalogItem, 2); context.Commit(); }
protected override void Seed(GlobalmanticsContext context) { context.CatalogItems.AddOrUpdate(x => x.Sku, CatalogItem.Create ( sku: "CAFE-314", description: "1 Pound Guatemalan Coffee Beans", unitPrice: 18.80m ), CatalogItem.Create ( sku: "CAFE-272", description: "1 Pound Ethiopian Coffee Beans", unitPrice: 6.60m ), CatalogItem.Create ( sku: "DR-4142", description: "Drum roasting kit", unitPrice: 425.00m )); }
private void InitializeCartWithOneItem(string databaseName) { var context = new GlobalmanticsContext(new DbContextOptionsBuilder() .UseInMemoryDatabase(databaseName) .Options); var user = context.Add(User.Create("*****@*****.**")) .Entity; context.SaveChanges(); var cart = context.Add(Cart.Create(user.UserId)).Entity; var catalogItem = context.Add(CatalogItem.Create ( sku: "CAFE-314", description: "1 Pound Guatemalan Coffee Beans", unitPrice: 18.80m )).Entity; cart.AddItem(catalogItem, 2); context.SaveChanges(); }
static IEnumerable <CatalogItem> GetPreconfiguredItems() { return(new List <CatalogItem>() { CatalogItem.Create( 1, 1, 10, 1200, "Rolleiflex 2.8GX", "Rolleiflex 2.8GX Camera", "28gx.jpg", "http://catalogbaseurl/images/products/28gx.jpg"), CatalogItem.Create( 1, 1, 10, 3800, "Rolleiflex 4.0 FW", "Rolleiflex 4.0 FW", "wide.jpg", "http://catalogbaseurl/images/products/wide.jpg"), CatalogItem.Create( 2, 1, 10, 1200, "Rolleiflex SL66", "Rolleiflex SL66 Camera", "sl66.jpg", "http://catalogbaseurl/images/products/sl66.jpg"), CatalogItem.Create( 2, 2, 10, 1200, "Hasselblad 500cm", "Hasselblad 500cm Camera", "500cm.jpg", "http://catalogbaseurl/images/products/500cm.jpg"), CatalogItem.Create( 3, 2, 10, 8000, "Hasselblad 205fcc", "Hasselblad 205fcc Camera", "205fcc.jpg", "http://catalogbaseurl/images/products/205fcc.jpg"), CatalogItem.Create( 2, 2, 10, 1600, "Hasselblad SWC", "Hasselblad SWC", "swc.jpg", "http://catalogbaseurl/images/products/swc.jpg"), CatalogItem.Create( 2, 3, 10, 600, "Mamiya RZ67", "Mamiya RZ67 Camera", "rz67.jpg", "http://catalogbaseurl/images/products/rz67.jpg"), CatalogItem.Create( 1, 3, 10, 300, "Mamiya C330", "Mamiya C330 Camera", "c330.jpg", "http://catalogbaseurl/images/products/c330.jpg"), CatalogItem.Create( 3, 3, 10, 1500, "Mamiya 6", "Mamiya 6 Camera", "mamiya6.jpg", "http://catalogbaseurl/images/products/mamiya6.jpg"), CatalogItem.Create( 3, 4, 10, 1200, "Fuji GF670", "Fuji GF670 Camera", "gf670.jpg", "http://catalogbaseurl/images/products/gf670.jpg"), CatalogItem.Create( 3, 4, 10, 550, "Fuji GS645", "Fuji GS645 Camera", "gs645.jpg", "http://catalogbaseurl/images/products/gs645.jpg"), }); }