private void button1_Click_1(object sender, EventArgs e) { try { IUser user = this.Users.GetItemById(Convert.ToInt32(inputOrderUserId.Text)); IOrderProps props = new OrderProps(); List <IProduct> ProductIds = inputOrderProductId.Text .Split(',', StringSplitOptions.RemoveEmptyEntries) .Select(x => x.Trim()) .Select(x => this.Products.GetItemById(Convert.ToInt32(x))) .ToList(); if (user is null || ProductIds.Contains(null)) { this.ShowMessage("Bruger eller Produkt findes ikke"); return; } props.user = user; props.products = ProductIds; this.Orders.AddItem(this.ItemsFactory.create(props)); this.ShowMessage("Ordre er oprettet succesfuldt"); } catch { this.ShowMessage("Noget gik galt.. prøv igen"); } }
public void CreateOrder() { try { bool _SelectingProducts = true; this.Print(this.Users.GetList()); Console.WriteLine("User Id:"); int UserId = Convert.ToInt32(Console.ReadLine()); IUser User = this.Users.GetItemById(UserId); List <IProduct> Products = new List <IProduct>(); while (_SelectingProducts) { this.Print(this.Products.GetList()); Console.WriteLine("Product Id:"); Products.Add(this.Products.GetItemById(Convert.ToInt32(Console.ReadLine()))); Console.WriteLine("Vil du tilføje flere produkter? Y = Yes --- N = No"); if (Console.ReadLine().ToLower() == "n") { _SelectingProducts = false; } } IOrderProps props = new OrderProps(); props.user = User; props.products = Products; props.id = Generator.getId("order"); if (Products.Count > 0) { this.Orders.AddItem(this.factory.create(props)); return; } Console.WriteLine("Product OR User doesnt exist"); Console.ReadLine(); } catch { this.CreateOrder(); } }