static int AddInvoice(int CustomerId, InvoiceData invoiceData, DateTime CreatedDate) { Invoice newInvoice = new Invoice { CustomerId = CustomerId, InvoiceDate = CreatedDate, InvoiceAmount = Convert.ToDecimal(invoiceData.InvoiceAmount), InvoiceType = invoiceData.InvoiceType }; SalesDbContext.Invoices.Add(newInvoice); SalesDbContext.SaveChanges(); int newInvoiceId = newInvoice.InvoiceId; SalesDbContext.SaveChanges(); foreach (InvoiceDetailData invoiceDetailData in invoiceData.InvoiceDetails) { newInvoice.InvoiceDetails.Add(new InvoiceDetail { InvoiceId = newInvoiceId, ProductId = invoiceDetailData.ProductId, Quantity = invoiceDetailData.Quantity, SalesAmount = Convert.ToDecimal(invoiceDetailData.Price) }); }; SalesDbContext.SaveChanges(); Console.Write("."); Customer customer = SalesDbContext.Customers.Find(CustomerId); if (customer != null) { customer.LastPurchaseDate = CreatedDate; SalesDbContext.SaveChanges(); } return newInvoiceId; }
public static InvoiceData GetNextInvoice() { invoiceCount += 1; int customerId = WingtipRandom.Next(1, customerCount); List<InvoiceDetailData> invoiceDetails = new List<InvoiceDetailData>(); int ItemCount = WingtipRandom.Next(1, 4); double InvoiceAmount = 0; for (int index = 0; index < ItemCount; index++) { int productId = GetProductId(); ProductData product = Products[productId - 1]; int quantity = WingtipRandom.Next(1, 10); double price = quantity * product.ListPrice; InvoiceAmount += price; invoiceDetails.Add(new InvoiceDetailData { ProductId = productId, Quantity = quantity, Price = price }); } string invoiceType = "InPerson"; switch (CustomerGrowthPhase) { case 1: // phase 1 if (WingtipRandom.Next(1, 100) > 90) { invoiceType = "MailOrder"; } break; case 2: // phase 2 if (WingtipRandom.Next(1, 100) > 95) { invoiceType = "MailOrder"; } if (WingtipRandom.Next(1, 100) > 50) { invoiceType = "Online"; } break; case 3: // phase 3 if (WingtipRandom.Next(1, 100) > 98) { invoiceType = "MailOrder"; } if (WingtipRandom.Next(1, 100) > 35) { invoiceType = "Online"; } break; case 4: // phase 4 if (WingtipRandom.Next(1, 100) > 99) { invoiceType = "MailOrder"; } if (WingtipRandom.Next(1, 100) > 24) { invoiceType = "Online"; } break; } InvoiceData newInvoice = new InvoiceData { InvoiceAmount = InvoiceAmount, InvoiceType = invoiceType, InvoiceDetails = invoiceDetails }; return newInvoice; }
public static CustomerData GetNextCustomer() { CustomerLocationData customerLocation = GetNextCustomerLocation(); string Address = GetNextAddress(); string City = customerLocation.City; string State = customerLocation.State; string ZipCode = customerLocation.ZipCode; string AreaCode = customerLocation.AreaCode; string WorkPhoneNumber = GetNextPhoneNumber(AreaCode); string HomePhoneNumber = GetNextPhoneNumber(AreaCode); string Gender = "F"; string invoiceType = "InPerson"; switch (CustomerGrowthPhase) { case 1: // phase 1 if (WingtipRandom.Next(1, 100) > 32) { Gender = "M"; } break; case 2: // phase 2 if (WingtipRandom.Next(1, 100) > 45) { Gender = "M"; } break; case 3: // phase 3 if (WingtipRandom.Next(1, 100) > 55) { Gender = "M"; } break; case 4: // phase 4 if (WingtipRandom.Next(1, 100) > 67) { Gender = "M"; } break; case 5: // phase 4 if (WingtipRandom.Next(1, 100) > 70) { Gender = "M"; } break; case 6: // phase 4 if (WingtipRandom.Next(1, 100) > 65) { Gender = "M"; } break; case 7: // phase 4 if (WingtipRandom.Next(1, 100) > 55) { Gender = "M"; } break; case 8: // phase 4 if (WingtipRandom.Next(1, 100) > 52) { Gender = "M"; } break; case 9: // phase 4 if (WingtipRandom.Next(1, 100) > 48) { Gender = "M"; } break; case 10: // phase 4 if (WingtipRandom.Next(1, 100) > 44) { Gender = "M"; } break; case 11: // phase 4 if (WingtipRandom.Next(1, 100) > 42) { Gender = "M"; } break; case 12: // phase 4 if (WingtipRandom.Next(1, 100) > 38) { Gender = "M"; } break; case 13: // phase 4 if (WingtipRandom.Next(1, 100) > 40) { Gender = "M"; } break; case 14: // phase 4 if (WingtipRandom.Next(1, 100) > 44) { Gender = "M"; } break; case 15: // phase 4 if (WingtipRandom.Next(1, 100) > 50) { Gender = "M"; } break; case 16: // phase 4 if (WingtipRandom.Next(1, 100) > 48) { Gender = "M"; } break; } string FirstName = ""; if (Gender.Equals("F")) { FirstName = GetNextFemaleFirstName(); } else { FirstName = GetNextMaleFirstName(); } string LastName = GetNextLastName(); string Company = GetNextCompany(); string EmailAddress = (FirstName + "." + LastName + "@" + Company + ".com").Replace(" ", "").Replace("'", ""); DateTime BirthDate = GetNextBirthDate(); if (State.Equals("FL")) { BirthDate = BirthDate.AddYears(-21); } if (State.Equals("AZ")) { BirthDate = BirthDate.AddYears(-12); } if (State.Equals("NM")) { BirthDate = BirthDate.AddYears(-9); } if (State.Equals("TX")) { BirthDate = BirthDate.AddYears(-7); } if (Gender.Equals("F")) { BirthDate = BirthDate.AddYears(-3); } List<InvoiceDetailData> invoiceDetails = new List<InvoiceDetailData>(); int ItemCount = WingtipRandom.Next(1, 4); double InvoiceAmount = 0; for (int index = 0; index < ItemCount; index++) { int productId = GetProductId(); ProductData product = Products[productId - 1]; int quantity = WingtipRandom.Next(1, 10); if (productId == 14) { int[] quantitySizes = { 10, 25, 25, 25, 100, 100, 100, 100, 100, 250, 250, 250, 500, 1000, 1000, 1000, 1000, 2500 }; int selection = WingtipRandom.Next(0, quantitySizes.Length - 1); quantity = quantitySizes[selection]; } double price = quantity * product.ListPrice; InvoiceAmount += price; invoiceDetails.Add(new InvoiceDetailData { ProductId = productId, Quantity = quantity, Price = price }); } InvoiceData FirstInvoice = new InvoiceData { InvoiceAmount = InvoiceAmount, InvoiceType = invoiceType, InvoiceDetails = invoiceDetails }; CustomerData newCustomer = new CustomerData { FirstName = FirstName, LastName = LastName, Company = Company, EmailAddress = EmailAddress, WorkPhone = WorkPhoneNumber, HomePhone = HomePhoneNumber, Address = Address, City = City, State = State, ZipCode = ZipCode, Gender = Gender, BirthDate = BirthDate, FirstInvoice = FirstInvoice }; customerCount += 1; return newCustomer; }