private static void UpdateSaleLineItem(Guid id) { using (var db = new SaleDbContext()) { var transaction = db.SaleLineItems.Find(id); transaction.ProductDescription += " changed"; transaction.Modified = DateTimeOffset.UtcNow; transaction.ModifiedBy = "test"; db.SaveChanges(); } }
private static void UpdateSale(Guid id) { using (var db = new SaleDbContext()) { var purchase = db.SaleHeaders.Find(id); purchase.CustomerName += " changed"; purchase.Modified = DateTimeOffset.UtcNow; purchase.ModifiedBy = "test"; db.SaveChanges(); } }
public void TestInitialize() { TestCleanup(); var totalNumber = default(int); using (var db = new SaleDbContext()) { if (db.SaleHeaders.Any()) { totalNumber = db.SaleHeaders.Max(s => s.TotalNumber); } } var sales = new List<SaleHeader>(55); for (int i = 0; i < sales.Capacity; i++) { var now = GenerateFakeNow(); var random = new Random(i); var sale = new SaleHeader() { DayNumber = sales.Count(s => s.Created.Date == now.Date) + 1, TotalNumber = totalNumber + i + 1, SalesPersonName = GenerateSalesPersonName(i), CustomerName = string.Format("customer {0}", i + 1), Status = GenerateEnumValue<SaleStatus>(), }; sale.NumberText = sale.GenerateSaleNumber(); sale.CustomerContacts = new[] { new Contact() { Method = ContactMethod.Phone, Value = string.Format("contact method phone number {0}", i + 1), }, new Contact() { Method = GenerateEnumValue<ContactMethod>(), Value = string.Format("contact method {0}", i + 1), }, }; sale.Items = new List<SaleLineItem>(); var length = random.Next(1, 5); for (int j = 0; j < length; j++) { var line = new SaleLineItem() { ProductName = GenerateProductName(), ProductDescription = null, Quantity = random.Next(1, 2), UnitPrice = (decimal)((random.NextDouble() + 0.1) * 10000), Status = GenerateEnumValue<SaleStatus>(), }; if (j % 2 == 0) { line.DynamicProperties.Add("Certificate", GenerateCertificate()); line.DynamicProperties.Add("Cut", GenerateCut()); line.DynamicProperties.Add("Caret", GenerateCaret()); line.DynamicProperties.Add("Color", GenerateColor()); line.DynamicProperties.Add("Clarity", GenerateClarity()); } sale.Items.Add(line); } FillCommonValues(sale, now); sales.Add(sale); } using (var db = new SaleDbContext()) { db.SaleHeaders.AddRange(sales); db.SaleLineItems.AddRange(sales.SelectMany(s => s.Items)); db.Contacts.AddRange(sales.SelectMany(s => s.CustomerContacts)); db.SaveChanges(); } }
private static void UpdateContact(Guid id) { using (var db = new SaleDbContext()) { var contact = db.Contacts.Find(id); contact.Value += " changed"; contact.Modified = DateTimeOffset.UtcNow; contact.ModifiedBy = "test"; db.SaveChanges(); } }
public void TestCleanup() { using (var db = new SaleDbContext()) { db.Database.ExecuteSqlCommand("DELETE tc_customer_contact"); db.Database.ExecuteSqlCommand("DELETE tc_sale_line"); db.Database.ExecuteSqlCommand("DELETE tc_sale_header"); db.SaveChanges(); } }