public Task <Guid> CreateAsync( StockRoom room, Dictionary <string, string> headers = default, CancellationToken ct = default) { return(_factory.PostAsync <Guid>(_host + "/Stock/Rooms/v1/Create", null, room, headers, ct)); }
public void AddSalesToStockAndDecrementProducts(SaleDto saleDto) { var newSale = new Sale() { SellingDate = saleDto.SellingDate, ClientId = saleDto.ClientId }; _shoesDataEntities.Sales.Add(newSale); foreach (var saleProductDto in saleDto.SalesProducts) { var currentProduct = _productServices.FindProduct( saleProductDto.ModelId, saleProductDto.ColorId, saleProductDto.Size); var newSaleProduct = new SaleProduct { ProductId = currentProduct.Id, SaleId = newSale.Id, Quantity = saleProductDto.Quantity, SellingPrice = saleProductDto.Price }; _shoesDataEntities.SaleProducts.Add(newSaleProduct); var lastStockRoom = _stockRoomDataServices.GetLastStockRoomByProductId(currentProduct.Id); var newStockRoom = new StockRoom() { ProductId = currentProduct.Id, StockValue = lastStockRoom.StockValue - saleProductDto.Quantity, EntryValue = -saleProductDto.Quantity, EntryDate = saleDto.SellingDate, OperationType = OperationType.OUT.ToString() }; _shoesDataEntities.StockRooms.Add(newStockRoom); SaveChanges(); } }
public Task UpdateAsync( StockRoom room, Dictionary <string, string> headers = default, CancellationToken ct = default) { return(_factory.PatchAsync(_host + "/Stock/Rooms/v1/Update", null, room, headers, ct)); }
public InventoryKafkaService(CafeKafkaSettings cafeKafkaSettings) { _stockRoom = new StockRoom(); try { _consumerConfig = new ConsumerConfig() { GroupId = cafeKafkaSettings.GroupId, BootstrapServers = cafeKafkaSettings.BootstrapServers, AutoOffsetReset = AutoOffsetReset.Earliest, SocketKeepaliveEnable = true, AllowAutoCreateTopics = true }; _producerConfig = new ProducerConfig() { BootstrapServers = cafeKafkaSettings.BootstrapServers }; Console.WriteLine("Read Kafka Bootstrap: " + cafeKafkaSettings.BootstrapServers); } catch (Exception ex) { Console.WriteLine("Exception in kafka settings: " + ex); } }
static void Main(string[] args) { var stockroom = new StockRoom(); new Setup().Execute(stockroom); var joe = new Customer(); var order = new OrderPlacedEvent(); order.Items.Add(new MillerLite()); order.Items.Add(new BaconCheeseBurger()); var kitchen = new Kitchen(); EventManager.Register<OrderPlacedEvent>(joe.PlaceOrder); EventManager.Register<OrderPlacedEvent>(stockroom.OrderPlaced); EventManager.Register<ItemMovedToKitchenEvent>(kitchen.Cook); EventManager.Register<OrderReadyEvent>(joe.ReceiveOrder); EventManager.Raise(order); //customer places order //stockroom moves order to kitchen //kithcen prepared order //waitstaff delivers order //waitstaff checks on customer //waitstaff delivers bill //customer pasys //marketing sends a thanks a lot email //waitstaff delivers reciept //Done! }
private StockRoom AddNewStockRoomUpdatingTotal(StockRoomDto newStockRoomDto) { var currentProduct = _productServices.FindProduct( newStockRoomDto.ModelId, newStockRoomDto.SelectedColor.ColorId, newStockRoomDto.Size); var lastStockRoom = GetLastStockRoomByProductId(currentProduct.Id); var stocks = newStockRoomDto.Quantity; if (lastStockRoom != null) { stocks += lastStockRoom.StockValue; } var newStockRoom = new StockRoom { ProductId = currentProduct.Id, StockValue = stocks, EntryValue = newStockRoomDto.Quantity, EntryDate = newStockRoomDto.EntryDate, OperationType = OperationType.IN.ToString(), SupplierId = newStockRoomDto.SupplierId }; _shoesDataEntities.StockRooms.Add(newStockRoom); return(newStockRoom); }
public async Task <ActionResult <Guid> > Create(StockRoom room, CancellationToken ct = default) { room.AccountId = _userContext.AccountId; var id = await _stockRoomsService.CreateAsync(_userContext.UserId, room, ct); return(Created(nameof(Get), id)); }
public void WhenAnOrderIsPlacedInventoryIsDepleted() { var sw = new StockRoom(); sw.AddDish(1, new Cheeseburger()); sw.AddDish(1, new CrabFries()); sw.OrderPlaced(new OrderPlacedEvent{ Items = new List<Dish> { new Cheeseburger(), new CrabFries()}}); Assert.AreEqual(0, sw.GetStockLevel<Cheeseburger>()); Assert.AreEqual(0, sw.GetStockLevel<CrabFries>()); }
public static StockRoomChange CreateWithLog(this StockRoom room, Guid userId, Action <StockRoom> action) { action(room); return(new StockRoomChange { StockRoomId = room.Id, ChangerUserId = userId, CreateDateTime = DateTime.UtcNow, OldValueJson = string.Empty, NewValueJson = room.ToJsonString() }); }
public StockRoomBuilder( IDefaultRequestHeadersService defaultRequestHeadersService, IStockRoomsClient orderTypesClient) { _orderTypesClient = orderTypesClient; _defaultRequestHeadersService = defaultRequestHeadersService; _room = new StockRoom { Id = Guid.NewGuid(), Name = "Test".WithGuid(), IsDeleted = false }; }
public async Task <ActionResult> Update(StockRoom room, CancellationToken ct = default) { var oldType = await _stockRoomsService.GetAsync(room.Id, true, ct); if (oldType == null) { return(NotFound(room.Id)); } return(await ActionIfAllowed( () => _stockRoomsService.UpdateAsync(_userContext.UserId, oldType, room, ct), Roles.Orders, oldType.AccountId)); }
public void WhenAnOrderIsPlacedInventoryIsDepleted() { var sw = new StockRoom(); sw.AddDish(1, new Cheeseburger()); sw.AddDish(1, new CrabFries()); sw.OrderPlaced(new OrderPlacedEvent { Items = new List <Dish> { new Cheeseburger(), new CrabFries() } }); Assert.AreEqual(0, sw.GetStockLevel <Cheeseburger>()); Assert.AreEqual(0, sw.GetStockLevel <CrabFries>()); }
public InventoryKafkaService(CafeKafkaSettings cafeKafkaSettings) { _stockRoom = new StockRoom(); try { _consumerConfig = KafkaConfig.CreateConsumerConfig(cafeKafkaSettings); _producerConfig = KafkaConfig.CreateProducerConfig(cafeKafkaSettings); Console.WriteLine("Read Kafka Bootstrap: " + cafeKafkaSettings.BootstrapServers); } catch (Exception ex) { Console.WriteLine("Exception in kafka settings: " + ex); } }
public async Task UpdateAsync( Guid userId, StockRoom oldRoom, StockRoom newRoom, CancellationToken ct) { var change = oldRoom.UpdateWithLog(userId, x => { x.Name = newRoom.Name; x.IsDeleted = newRoom.IsDeleted; x.ModifyDateTime = DateTime.UtcNow; }); _storage.Update(oldRoom); await _storage.AddAsync(change, ct); await _storage.SaveChangesAsync(ct); }
public void Execute(StockRoom stockRoom) { stockRoom.AddDish(10, new Cheeseburger()); stockRoom.AddDish(10, new BaconCheeseBurger()); stockRoom.AddDish(10, new PotPie()); stockRoom.AddDish(10, new CheeseSteak()); stockRoom.AddDish(10, new CrabFries()); stockRoom.AddDish(10, new HotWings()); stockRoom.AddDish(10, new Fries()); stockRoom.AddDish(10, new MillerLite()); stockRoom.AddDish(10, new CoorsLite()); stockRoom.AddDish(10, new Soda()); stockRoom.AddDish(10, new IcedTea()); stockRoom.AddDish(10, new Nachos()); stockRoom.AddDish(10, new BlackenedChickenSandwich()); stockRoom.AddDish(10, new Pizza()); stockRoom.AddDish(10, new Calzone()); stockRoom.AddDish(10, new VealScallopini()); }
public void Execute(StockRoom stockRoom) { stockRoom.AddDish(10, new Cheeseburger()); stockRoom.AddDish(10, new BaconCheeseBurger()); stockRoom.AddDish(10, new PotPie()); stockRoom.AddDish(10, new CheeseSteak()); stockRoom.AddDish(10, new CrabFries()); stockRoom.AddDish(10, new HotWings()); stockRoom.AddDish(10, new Fries()); stockRoom.AddDish(10, new MillerLite()); stockRoom.AddDish(10, new CoorsLite()); stockRoom.AddDish(10, new Soda()); stockRoom.AddDish(10, new IcedTea()); stockRoom.AddDish(10, new Nachos()); stockRoom.AddDish(10, new BlackenedChickenSandwich()); stockRoom.AddDish(10, new Pizza()); stockRoom.AddDish(10, new Calzone()); stockRoom.AddDish(10, new VealScallopini()); }
public async Task <Guid> CreateAsync(Guid userId, StockRoom room, CancellationToken ct) { var newRoom = new StockRoom(); var change = newRoom.CreateWithLog(userId, x => { x.Id = room.Id; x.AccountId = room.AccountId; x.Name = room.Name; x.IsDeleted = room.IsDeleted; x.CreateDateTime = DateTime.UtcNow; }); var entry = await _storage.AddAsync(newRoom, ct); await _storage.AddAsync(change, ct); await _storage.SaveChangesAsync(ct); return(entry.Entity.Id); }
public async Task WhenCreate_ThenSuccess() { var headers = await _defaultRequestHeadersService.GetAsync(); var room = new StockRoom { Id = Guid.NewGuid(), Name = "Test".WithGuid(), IsDeleted = false }; var createdTypeId = await _stockRoomsClient.CreateAsync(room, headers); var createdType = await _stockRoomsClient.GetAsync(createdTypeId, headers); Assert.NotNull(createdType); Assert.Equal(createdTypeId, createdType.Id); Assert.Equal(room.Name, createdType.Name); Assert.Equal(room.IsDeleted, createdType.IsDeleted); Assert.True(createdType.CreateDateTime.IsMoreThanMinValue()); }
static void Main(string[] args) { var stockroom = new StockRoom(); new Setup().Execute(stockroom); var joe = new Customer(); var order = new OrderPlacedEvent(); order.Items.Add(new MillerLite()); order.Items.Add(new BaconCheeseBurger()); var kitchen = new Kitchen(); EventManager.Register <OrderPlacedEvent>(joe.PlaceOrder); EventManager.Register <OrderPlacedEvent>(stockroom.OrderPlaced); EventManager.Register <ItemMovedToKitchenEvent>(kitchen.Cook); EventManager.Register <OrderReadyEvent>(joe.ReceiveOrder); EventManager.Raise(order); //customer places order //stockroom moves order to kitchen //kithcen prepared order //waitstaff delivers order //waitstaff checks on customer //waitstaff delivers bill //customer pasys //marketing sends a thanks a lot email //waitstaff delivers reciept //Done! }
private StockRoom AddNewStockRoomAndProduct(StockRoomDto newStockRoomDto, int colorId) { var currentProduct = new Product { ModelId = newStockRoomDto.ModelId, ColorId = colorId, Size = newStockRoomDto.Size, }; _shoesDataEntities.Products.Add(currentProduct); var newStockRoom = new StockRoom { ProductId = currentProduct.Id, StockValue = newStockRoomDto.Quantity, EntryValue = newStockRoomDto.Quantity, EntryDate = newStockRoomDto.EntryDate, OperationType = OperationType.IN.ToString(), SupplierId = newStockRoomDto.SupplierId }; _shoesDataEntities.StockRooms.Add(newStockRoom); return(newStockRoom); }
public void SupplyStoreStockRoom(StoreStockRoomDto storeStockRoomDto) { if (storeStockRoomDto.ColorId == null) { throw new InvalidOperationException("Error: No enter new Store StockRoom if Color is null"); } if (storeStockRoomDto.Size == null) { throw new InvalidOperationException("Error: No enter new Store StockRoom if Shoes Size is null"); } var modelId = storeStockRoomDto.ModelId; var colorId = storeStockRoomDto.ColorId.Value; var size = storeStockRoomDto.Size.Value; var currentProduct = _productServices.FindProduct(modelId, colorId, size); if (currentProduct == null) { throw new StockRoomOperationException("No Found a product item to supply Store StockRoom"); } var lastStockRoom = _stockRoomDataServices.GetLastStockRoomByProductId(currentProduct.Id); if (lastStockRoom == null) { throw new StockRoomOperationException("No Found any stock room to execute the operation"); } if (lastStockRoom.StockValue < storeStockRoomDto.Quantity) { throw new StockRoomOperationException( "It is not possible to move requested quantity to selected store"); } var newStockRoom = new StockRoom() { ProductId = lastStockRoom.ProductId, StockValue = lastStockRoom.StockValue - storeStockRoomDto.Quantity, EntryDate = storeStockRoomDto.DateOfSupplier, EntryValue = -storeStockRoomDto.Quantity, StoreId = storeStockRoomDto.StoreId, OperationType = OperationType.OUT.ToString() }; _shoesDataEntities.StockRooms.Add(newStockRoom); var lastStoreStockRoom = GetLastStoreStockRoomByProductId(storeStockRoomDto.StoreId, currentProduct.Id); var storeStocks = storeStockRoomDto.Quantity; if (lastStoreStockRoom != null) { storeStocks += lastStoreStockRoom.StockValue; } var newStoreStockRoom = new StoreStockRoom { ProductId = currentProduct.Id, StockValue = storeStocks, EntryDate = storeStockRoomDto.DateOfSupplier, EntryValue = storeStockRoomDto.Quantity, StoreId = storeStockRoomDto.StoreId, OperationType = OperationType.IN.ToString() }; _shoesDataEntities.StoreStockRooms.Add(newStoreStockRoom); SaveChanges(); }