private static void RegisterOrder() { bool showMenu = true; WriteLine("Kund (personr.):"); string socialSecurityNumber = ReadLine(); Order order = new Order(); Customer customer = Context.Customer.FirstOrDefault(customer => customer.SocialSecurityNumber == socialSecurityNumber); while (showMenu) { if (customer != null) { Clear(); WriteLine($"{customer.FirstName} {customer.LastName}, {customer.SocialSecurityNumber}"); WriteLine(); WriteLine("Artikel"); WriteLine("-------------------------------------------"); foreach (ArticleOrder articleOrder in order.Articles) { WriteLine(articleOrder.Article.Name); } WriteLine(); WriteLine("(L)ägg till (S)kapa order"); ConsoleKeyInfo keyPressed = ReadKey(true); switch (keyPressed.Key) { case ConsoleKey.L: Clear(); WriteLine("Art.nmr"); string articleNumber = ReadLine(); Article article = Context.Article.FirstOrDefault(x => x.ArticleNumber == articleNumber); ArticleOrder articleOrder = new ArticleOrder(article); order.Articles.Add(articleOrder); showMenu = true; break; case ConsoleKey.S: Clear(); customer.Order.Add(order); Context.SaveChanges(); WriteLine("Order created"); Thread.Sleep(2000); showMenu = false; break; } } else { Clear(); WriteLine("Kund finns ej"); Thread.Sleep(2000); showMenu = false; } } }
internal override void Load() { using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext()) { Guid id = ItemId; Guid ordId = OrderId; ProductArticleItem articleItem = dataContext.ProductArticleItems.Find(id); ProductArticleReservation reservation = articleItem.ProductArticleReservations.FirstOrDefault(r => r.ProductArticleOrderId == ordId); ArticleId = articleItem.ArticleId; Code = articleItem.Article.Code; Type = articleItem.Article.ArticleType; Name = articleItem.Article.Name; Count = articleItem.Quantity; StockAvailable = reservation != null ? reservation.CurrentCount : 0; Storage = articleItem.Storage.Name; ProductionReservation = reservation != null ? reservation.ReservationCount : 0; OrderCount = reservation != null ? reservation.OrderCount : 0; if (Type == ArticleType.Card) { ArticleOrder articleOrder = dataContext.ArticleOrders.FirstOrDefault(ao => ao.ArticleId == articleItem.ArticleId); if (reservation != null && Math.Abs(reservation.OrderCount - 0) < 0.001) { articleOrder = null; } MaterialOrderStatus = new MaterialOrderStatus(DataChange, articleOrder != null ? articleOrder.Count : 0, articleOrder != null ? articleOrder.Article.OrderCount : 0); } else { MaterialOrderStatus = new MaterialOrderStatus(DataChange, 0, 0); } } }
internal override void Load() { using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext()) { Guid id = MaterialId; ArticleOrder articleOrder = dataContext.ArticleOrders.FirstOrDefault(o => o.ArticleId == id); if (articleOrder == null) { return; } OrderId = articleOrder.Id; Code = articleOrder.Article.Code; Name = articleOrder.Article.Name; CurrentCount = articleOrder.Article.ArticleStat.CurrentCount; OrderedCount = articleOrder.Count; CurrentTotalCount = articleOrder.Article.ArticleStat.CurrentCount + articleOrder.Article.ExternStorageCount; MaterialOrderStatus = new MaterialOrderStatus(DataChange, articleOrder.Count, articleOrder.Article.OrderCount); } }