public ActionResult ChangePassword(ChangePasswordViewModel model) { if (ModelState.IsValid) { User user = db.Users.FirstOrDefault(l => l.Login == model.Login); if (user != null) { string hashPassword = CryptHelper.CreateHashMD5(model.Password); user.Password = hashPassword; db.SaveChanges(); var userAdmin = Session["UserAdminFromIndex"]; if (userAdmin != null && (bool)userAdmin) { Session["UserAdminFromIndex"] = null; return(RedirectToAction("Index")); } else { return(RedirectToAction("Index", "Product")); } } else { return(HttpNotFound()); } } return(View(model)); }
public ActionResult Create([Bind(Include = "Name, City")] Provider provider) { if (ModelState.IsValid) { db.Providers.Add(provider); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(provider)); }
public ActionResult Create([Bind(Include = "Name")] TypeProduct typeProduct) { if (ModelState.IsValid) { db.TypeProducts.Add(typeProduct); db.SaveChanges(); return(RedirectToAction("Index")); } return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "SupplierId,Name,Address,State")] Supplier supplier) { if (ModelState.IsValid) { db.Suppliers.Add(supplier); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(supplier)); }
public IActionResult Insert([FromBody] Customer customer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Customers.Add(customer); _context.SaveChanges(); return(Created(new Uri(Request.GetDisplayUrl() + "/" + customer.Id), customer)); }
public ActionResult Create([Bind(Include = "ProductId,Name,QtyStock,DateOfPurchase")] Product product) { ViewBag.SupplierNames = db.Suppliers.Select(x => x.Name).ToList(); if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
public bool Create(Category c) { try { _db.Categories.Add(c); _db.SaveChanges(); return(true); } catch (Exception e) { Console.WriteLine(e.StackTrace); return(false); } }
public ActionResult Create([Bind(Include = "ProductId, ReturnDate, Price, TypeReturnId")] Return newReturn) { if (ModelState.IsValid) { User user = UserEntities.GetUserByName(User.Identity.Name); newReturn.CreateDate = DateTime.Now; if (user != null) { newReturn.UserId = user.Id; } else { return(HttpNotFound()); } Product product = db.Products.Where(i => i.Id == newReturn.ProductId).FirstOrDefault(); if (product != null) { product.Count = product.Count + 1; } else { return(HttpNotFound()); } db.Returns.Add(newReturn); db.SaveChanges(); return(RedirectToAction("Index")); } return(RedirectToAction("Create")); }
public ActionResult Register(RegisterViewModel model) { if (ModelState.IsValid) { User newUser = new User(); Role role = db.Roles.FirstOrDefault(u => u.Name == "user"); string hashPassword = CryptHelper.CreateHashMD5(model.Password); newUser.Login = model.Login; newUser.FIO = model.FIO; newUser.Password = hashPassword; newUser.Roles.Add(role); db.Users.Add(newUser); db.SaveChanges(); newUser = db.Users.Where(u => u.Login == model.Login && u.Password == hashPassword).FirstOrDefault(); // если пользователь удачно добавлен в бд, то создаем куки if (newUser != null) { FormsAuthentication.SetAuthCookie(model.Login, true); return(RedirectToAction("Index", "Product")); } else { return(HttpNotFound()); } } return(View(model)); }
public ActionResult Create(TransactionRowViewModel viewModel) { if (ModelState.IsValid) { using (var ctx = new SalesDbContext()) { var transact = new Transaction() { PayMethod = viewModel.Payment, Sales = viewModel.SalesList }; foreach (Sale s in viewModel.SalesList) { ProductLog.GenerateSaleLog(ctx, s.Product, s.QTY); s.Update(); } transact.Update(); ctx.Transactions.Add(transact); ctx.SaveChanges(); return(RedirectToAction("Read", new { id = transact.ID })); } } return(View(viewModel)); }
public async Task <ActionResult> Post([FromForm] RequestModel requestModel) { if (requestModel.formFile == null) { ModelState.AddModelError("formFile", "Please upload the file."); return(BadRequest(ModelState)); } var result = await _fileParser.Read(requestModel.formFile.OpenReadStream()); var entities = result .Where(y => y.TotalSalesAmount > requestModel.minimumSalesAmount && y.Timestamp < DateTimeOffset.UtcNow) .Select(x => new CustomerSales() { CustomerId = x.CustomerId, CustomerName = x.CustomerName, CustomerType = x.CustomerType, TotalSalesAmount = x.TotalSalesAmount, Timestamp = x.Timestamp, CreatedOn = DateTimeOffset.UtcNow, UpdatedOn = DateTimeOffset.UtcNow }).ToList(); await _dbContext.AddRangeAsync(entities); _dbContext.SaveChanges(); return(Ok()); }
public ActionResult Create([Bind(Include = "Name, Model, Color, Size, RetailPrice, ProviderId, TypeProductId")] Product product, HttpPostedFileBase image) { if (ModelState.IsValid) { if (image != null) { product.Image = SaveAsImage(image); } product.CreateDate = DateTime.Now; db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
public static void EnsureTestdataSeeding(this SalesDbContext context) { EnsureDataSeeded(context); if (!context.Customer.Any()) { context.Customer.AddRange(SeedDataBuilder.BuildTypeCollectionFromFile <Customer>()); context.SaveChanges(); } }
public bool Create(Product p) { try { Category c = _db.Categories.Single(c => c.Id == p.Category.Id); p.Category = c; _db.Products.Add(p); _db.SaveChanges(); return(true); } catch (Exception e) { Console.WriteLine(e.StackTrace); return(false); } }
public ActionResult DeleteConfirmed(Guid id) { using (var ctx = new SalesDbContext()) { Report report = ctx.Reports.Find(id); ctx.Reports.Remove(report); ctx.SaveChanges(); return(RedirectToAction("Index")); } }
public ActionResult DeleteConfirmed(Guid id) { using (var ctx = new SalesDbContext()) { Product product = ctx.Products.FirstOrDefault(); //ctx.Products.Find(id) //ctx.Products.Remove(product); product.Discontinued = true; ctx.SaveChanges(); return(RedirectToAction("Index")); } }
public ActionResult Create([Bind(Include = "CostsDate, Price, Comment")] OtherCosts newOtherCost) { if (ModelState.IsValid) { newOtherCost.CreateDate = DateTime.Now; db.OtherCosts.Add(newOtherCost); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(newOtherCost)); }
public ActionResult Edit(Report report) { if (ModelState.IsValid) { using (var ctx = new SalesDbContext()) { ctx.Entry(report).State = EntityState.Modified; ctx.SaveChanges(); return(RedirectToAction("Index")); } } return(View(report)); }
private void AddDefaultAdmin(SalesDbContext context) { var userManager = new UserManager <Admin>(new UserStore <Admin>(context)); var passwordHash = new PasswordHasher(); string password = passwordHash.HashPassword("123456"); var mainAdmin = new Admin { Email = "*****@*****.**", UserName = "******", PasswordHash = password, SecurityStamp = Guid.NewGuid().ToString("D") }; context.Users.Add(mainAdmin); context.SaveChanges(); userManager.AddToRole(mainAdmin.Id, RoleNames.MainAdmin); }
public ActionResult Create([Bind(Include = "RetailPrice, Discount, SaleDate, ProductId")] Sale sale, bool?emptingSale) { if (ModelState.IsValid) { User user = UserEntities.GetUserByName(User.Identity.Name); sale.CreateDate = DateTime.Now; if (user != null) { sale.UserId = user.Id; } else { return(HttpNotFound()); } if (emptingSale != null && emptingSale == true) { sale.SaleDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); } else { if (sale.Discount != null) { sale.SalePrice = sale.RetailPrice - (int)sale.Discount; } else { sale.SalePrice = sale.RetailPrice; } Product product = db.Products.Where(i => i.Id == sale.ProductId).FirstOrDefault(); if (product != null) { product.Count = product.Count - 1; } else { return(HttpNotFound()); } } db.Sales.Add(sale); db.SaveChanges(); return(RedirectToAction("Create", new { createSale = true })); } return(RedirectToAction("Create")); }
public ActionResult Create(Report report) { if (ModelState.IsValid) { using (var ctx = new SalesDbContext()) { report.Update(); ctx.Reports.Add(report); ctx.SaveChanges(); return(RedirectToAction("Index")); } } return(View(report)); }
private void AddDefaultRoles(SalesDbContext context) { var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context)); var mainAdminRole = new IdentityRole { Name = RoleNames.MainAdmin }; var AdminRole = new IdentityRole { Name = RoleNames.Admin }; roleManager.Create(mainAdminRole); roleManager.Create(AdminRole); context.SaveChanges(); }
static void Main(string[] args) { var id = new Random().Next(1, 10000); using (var context = new SalesDbContext()) { var order = new Order(id, DateTime.Now, "Hadi Ahmadi"); order.AddOrderItem(new OrderItem("Western Digital 1TB HDD", 1, 2000000)); order.AddOrderItem(new OrderItem("Adata Premier PC3-12800 4GB DDR3", 2, 1300000)); context.Orders.Add(order); context.SaveChanges(); } Console.ReadLine(); }
public ActionResult Create([Bind(Include = "ID,Name,QTY,Price,Discontinued")] Product product) { using (var ctx = new SalesDbContext()) { if (ModelState.IsValid) { product.ID = Guid.NewGuid(); ctx.Products.Add(product); ProductLog.GenerateProductLog(ctx, product, product.QTY); ctx.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); } }
public bool Update([FromBody] Model.SalesData salesInfo) { if (!ModelState.IsValid) { return(false); } bool _result = true; //Add records to payment table first _dbContext.Payment.Add( new Payment() { CustomerId = salesInfo.CustomerId, InvoiceNumber = salesInfo.SalesInvoiceNumber, OpeningDebt = salesInfo.openingdebt, Currency = salesInfo.Currency, OperatorId = salesInfo.OperatorName } ); _dbContext.SaveChanges(); //get the Id int _id = _dbContext.Payment.FirstOrDefault(x => x.InvoiceNumber == salesInfo.SalesInvoiceNumber && x.CustomerId == salesInfo.CustomerId && x.OperatorId == salesInfo.OperatorName ).PaymentId; //Add records to payment details table foreach (var _payment in salesInfo.Payments) { _dbContext.PaymentDetails.Add( new PaymentDetails() { PaymentId = _id, RecNo = _payment.RecNo, PaymentTime = _payment.Paymentdate, Description = _payment.Description, Amount = _payment.Amount } ); } return(_result); }
//TODO FINISH THE METHOD LAST public static void Seed(SalesDbContext dbContext) { var storeNames = File.ReadAllLines(@"D:\SalesDataBaseCodeFirstEntityFrameworkCore\Data\RandomStoreNames.txt"); foreach (var storeName in storeNames) { dbContext.Stores.Add(new Store { StoreName = storeName }); } dbContext.SaveChanges(); var productNames = File.ReadAllLines(@"D:\SalesDataBaseCodeFirstEntityFrameworkCore\Data\RandomProductNames.txt"); foreach (var productName in productNames) { //dbContext.Products.Add() } }
public void SimpleHappyFlow_ShoppingBasketItemTest() { //Arrange var currentDateTime = DateTime.UtcNow; var shoppingCartItems = new List <ShoppingBasketItem>(); var shoppingBasketId = Guid.NewGuid(); //seedProducts.Add(new ShoppingBasketProduct() {ProductId =10, ProductName="ML Mountain Seat Assembly",Price = 147.14m }); shoppingCartItems.Add(new ShoppingBasketItem() { ShoppingBasketID = shoppingBasketId, ProductID = 514, Quantity = 4, DateCreated = currentDateTime, ModifiedDate = currentDateTime }); shoppingCartItems.Add(new ShoppingBasketItem() { ShoppingBasketID = shoppingBasketId, ProductID = 515, Quantity = 2, DateCreated = currentDateTime, ModifiedDate = currentDateTime }); using (var context = new SalesDbContext(_options)) { foreach (var item in shoppingCartItems) { context.ShoppingBasketItems.Add(item); } //Act context.SaveChanges(); //Assert var results = context.ShoppingBasketItems.Where(x => x.ShoppingBasketID == shoppingBasketId); results.Should().NotBeNullOrEmpty(); results.Count().Should().Be(2); var prod1 = results.Where(x => x.ProductID == 514).SingleOrDefault(); var prod2 = results.Where(x => x.ProductID == 515).SingleOrDefault(); prod1.Should().NotBeNull(); prod1.Quantity.Should().Be(4); prod1.DateCreated.Should().Be(currentDateTime); prod1.ModifiedDate.Should().Be(currentDateTime); prod2.Should().NotBeNull(); prod2.Quantity.Should().Be(2); prod2.DateCreated.Should().Be(currentDateTime); prod2.ModifiedDate.Should().Be(currentDateTime); } }
public ActionResult Edit([Bind(Include = "ID,Name,QTY,Price,Discontinued")] Product product) { using (var ctx = new SalesDbContext()) { if (ModelState.IsValid) { var oldProduct = ctx.Products.Where(x => x.ID == product.ID).FirstOrDefault(); oldProduct.Name = product.Name; oldProduct.QTY = product.QTY; oldProduct.LowWarn = product.LowWarn; oldProduct.Price = product.Price; oldProduct.Discontinued = product.Discontinued; ProductLog.GenerateProductLog(ctx, product, -product.QTY); ctx.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); } }
public Task Consume(ConsumeContext <ProductChangedModel> context) { _logger.LogInformation("Consume incoming event"); var shoppingBasketProduct = _salesDbContext.ShoppingBasketProducts.Where(x => x.ProductId == context.Message.ProductId).FirstOrDefault(); //Validate is productid is valid if (shoppingBasketProduct == null) { _salesDbContext.ShoppingBasketProducts.Add(new ShoppingBasketProduct() { ProductId = context.Message.ProductId, Price = context.Message.Price, ProductName = context.Message.Description }); } else { shoppingBasketProduct.Price = context.Message.Price; } var result = _salesDbContext.SaveChanges(); _logger.LogInformation("Incoming event consumed"); return(Task.FromResult(result)); }
public static void Main(string[] args) { AppDomain.CurrentDomain.SetData("DataDirectory", Path.GetFullPath("..\\..\\..\\PHP.Sales.Web\\App_Data")); using (var ctx = new SalesDbContext()) { ctx.Database.Delete(); ctx.Database.CreateIfNotExists(); //CREATE YOUR OBJECTS //CREATE THE PRODUCTS List <Product> prods = new List <Product>(new Product[] { new Product() { Name = "Panodol", Price = 12.32m, QTY = 30 }, new Product() { Name = "Nurofen", Price = 6.32m, QTY = 40 }, new Product() { Name = "Anti-Fungal", Price = 7.29m, QTY = 10 }, new Product() { Name = "Antibiotic", Price = 8.99m, QTY = 5 }, new Product() { Name = "Antihistermine", Price = 18.02m, QTY = 10 }, new Product() { Name = "Sunscreen", Price = 3372.5m, QTY = 1000 }, new Product() { Name = "Multivitamin 90", Price = 112400.00m, QTY = 7500 }, new Product() { Name = "Vitamin D", QTY = 1000.00m, Price = 8990.00m, }, new Product() { Name = "HS Pain Killer", QTY = 10m, Price = 8.99m, }, new Product() { Name = "Baby Paracetemol", QTY = 5.00m, Price = 12.59m, }, new Product() { Name = "Cold and Flu 24", QTY = 4.00m, Price = 7.29m, }, }); foreach (Product p in prods) { p.Update(); ProductLog.GenerateProductLog(ctx, p, p.QTY); } ctx.Products.AddRange(prods); //CREATE THE TRANSACTIONS //First Transaction and Sale var tran1 = new Transaction() { PayMethod = PaymentType.VISA, SaleTime = DateTime.Now }; var sale11 = new Sale() { Product = prods[0], QTY = 4.00m, Price = 12.32m, GST = true, Void = false, }; //Second Transaction and Sale var tran2 = new Transaction() { PayMethod = PaymentType.CASH, SaleTime = DateTime.Now, }; var sale21 = new Sale() { Product = prods[1], QTY = 2.00m, Price = 6.32m, GST = true, Void = false, }; var sale22 = new Sale() { Product = prods[0], QTY = 3.00m, Price = 9.24m, GST = true, Void = false, }; //Third Transaction and Sale var tran3 = new Transaction() { PayMethod = PaymentType.MASTERCARD, SaleTime = DateTime.Now, }; var sale31 = new Sale() { Product = prods[2], QTY = 1.00m, Price = 7.29m, GST = true, Void = false, }; var sale32 = new Sale() { Product = prods[3], QTY = 1.00m, Price = 8.99m, GST = false, Void = false, }; var sale33 = new Sale() { Product = prods[4], QTY = 2.00m, Price = 18.02m, GST = true, Void = false, }; //Fourth Transaction and Sale (Large Quantities) var tran4 = new Transaction() { PayMethod = PaymentType.CASH, SaleTime = DateTime.Now, }; var sale41 = new Sale() { Product = prods[5], QTY = 250.00m, Price = 3372.5m, GST = true, Void = false, }; var sale42 = new Sale() { Product = prods[6], QTY = 5000.00m, Price = 112400.00m, GST = true, Void = false, }; var sale43 = new Sale() { Product = prods[7], QTY = 1000.00m, Price = 8990.00m, GST = true, Void = false, }; //Fifth Transaction and Sale (One of Everything) var tran5 = new Transaction() { PayMethod = PaymentType.CASH, SaleTime = DateTime.Now, }; var sale51 = new Sale() { Product = prods[0], QTY = 1.00m, Price = 3.08m, GST = true, Void = false, }; var sale52 = new Sale() { Product = prods[1], QTY = 1.00m, Price = 3.16m, GST = true, Void = false, }; var sale53 = new Sale() { Product = prods[2], QTY = 1.00m, Price = 9.02m, GST = true, Void = false, }; var sale54 = new Sale() { Product = prods[5], QTY = 1.00m, Price = 13.49m, GST = true, Void = false, }; var sale55 = new Sale() { Product = prods[6], QTY = 1.00m, Price = 22.48m, GST = true, Void = false, }; var sale56 = new Sale() { Product = prods[7], QTY = 10.00m, Price = 8.99m, GST = true, Void = false, }; var sale57 = new Sale() { Product = prods[4], QTY = 1.00m, Price = 8.99m, GST = false, Void = false, }; var sale58 = new Sale() { Product = prods[8], QTY = 1.00m, Price = 8.99m, GST = false, Void = false, }; var sale59 = new Sale() { Product = prods[9], QTY = 1.00m, Price = 12.59m, GST = true, Void = false, }; var sale510 = new Sale() { Product = prods[2], QTY = 1.00m, Price = 7.29m, GST = true, Void = false, }; var sale511 = new Sale() { Product = prods[10], QTY = 1.00m, Price = 7.29m, GST = true, Void = false, }; //Sixth Sale and Trnasaction var tran6 = new Transaction() { PayMethod = PaymentType.VISA, SaleTime = DateTime.Now, }; var sale61 = new Sale() { Product = prods[10], QTY = 1.00m, Price = 7.29m, GST = true, Void = false, }; var sale62 = new Sale() { Product = prods[8], QTY = 1.00m, Price = 8.99m, GST = false, Void = false, }; var sale63 = new Sale() { Product = prods[6], QTY = 1.00m, Price = 22.48m, GST = true, Void = false, }; //Seventh Sale and Transaction (Same product sold multiple times) var tran7 = new Transaction() { PayMethod = PaymentType.MASTERCARD, SaleTime = DateTime.Now, }; var sale71 = new Sale() { Product = prods[6], QTY = 10.00m, Price = 224.80m, GST = true, Void = false, }; var sale72 = new Sale() { Product = prods[6], QTY = 1.00m, Price = 22.48m, GST = true, Void = false, }; var sale73 = new Sale() { Product = prods[6], QTY = 1.00m, Price = 22.48m, GST = true, Void = false, }; var sale74 = new Sale() { Product = prods[10], QTY = 1.00m, Price = 7.29m, GST = true, Void = false, }; var sale75 = new Sale() { Product = prods[6], QTY = 1.00m, Price = 22.48m, GST = true, Void = false, }; //Update Sale 7 sale71.Update(); sale72.Update(); sale73.Update(); sale74.Update(); sale75.Update(); tran7.Sales.Add(sale71); tran7.Sales.Add(sale72); tran7.Sales.Add(sale73); tran7.Sales.Add(sale74); tran7.Sales.Add(sale75); foreach (Sale s in tran7.Sales) { ProductLog.GenerateSaleLog(ctx, s.Product, s.QTY); } tran7.Update(); ctx.Transactions.Add(tran7); //Update Sale 6 sale61.Update(); sale62.Update(); sale63.Update(); tran6.Sales.Add(sale61); tran6.Sales.Add(sale62); tran6.Sales.Add(sale63); foreach (Sale s in tran6.Sales) { ProductLog.GenerateSaleLog(ctx, s.Product, s.QTY); } tran6.Update(); ctx.Transactions.Add(tran6); //Update Sale 5 sale51.Update(); sale52.Update(); sale53.Update(); sale54.Update(); sale55.Update(); sale56.Update(); sale57.Update(); sale58.Update(); sale59.Update(); sale510.Update(); sale511.Update(); tran5.Sales.Add(sale51); tran5.Sales.Add(sale52); tran5.Sales.Add(sale53); tran5.Sales.Add(sale54); tran5.Sales.Add(sale55); tran5.Sales.Add(sale56); tran5.Sales.Add(sale57); tran5.Sales.Add(sale58); tran5.Sales.Add(sale59); tran5.Sales.Add(sale510); tran5.Sales.Add(sale511); foreach (Sale s in tran5.Sales) { ProductLog.GenerateSaleLog(ctx, s.Product, s.QTY); } tran5.Update(); ctx.Transactions.Add(tran5); //Update Sale 4 sale41.Update(); sale42.Update(); sale43.Update(); tran4.Sales.Add(sale41); tran4.Sales.Add(sale42); tran4.Sales.Add(sale43); foreach (Sale s in tran4.Sales) { ProductLog.GenerateSaleLog(ctx, s.Product, s.QTY); } tran4.Update(); ctx.Transactions.Add(tran4); //Update Sale 3 sale31.Update(); sale32.Update(); sale33.Update(); tran3.Sales.Add(sale31); tran3.Sales.Add(sale32); tran3.Sales.Add(sale33); foreach (Sale s in tran3.Sales) { ProductLog.GenerateSaleLog(ctx, s.Product, s.QTY); } tran3.Update(); ctx.Transactions.Add(tran3); //Update Sale 2 sale21.Update(); sale22.Update(); tran2.Sales.Add(sale21); tran2.Sales.Add(sale22); foreach (Sale s in tran2.Sales) { ProductLog.GenerateSaleLog(ctx, s.Product, s.QTY); } tran2.Update(); ctx.Transactions.Add(tran2); //Update Sale 1 sale11.Update(); tran1.Sales.Add(sale11); foreach (Sale s in tran1.Sales) { ProductLog.GenerateSaleLog(ctx, s.Product, s.QTY); } tran1.Update(); ctx.Transactions.Add(tran1); //ADD REPORT List <Report> reports = new List <Report>() { new Report() { Name = "Test Report", Product = prods[0], Start = DateTime.Now, End = DateTime.Now.AddDays(1) }, new Report() { Name = "Test Weekly Report", Product = prods[2], Start = DateTime.Now.AddDays(-7), End = DateTime.Now.AddDays(-1) }, new Report() { Name = "Test Monthly Report", Product = prods[2], Start = DateTime.Now.AddMonths(-1), End = DateTime.Now.AddDays(-1) } }; foreach (var r in reports) { r.Update(); } ctx.Reports.AddRange(reports); //ADD STOCK SNAPSHOT List <Stock> snapshots = new List <Stock>() { /*new Stock() * { * Product = prods[0], * TimeStamp = DateTime.Now.Date, * QTY = 30 * }, * new Stock() * { * Product = prods[0], * TimeStamp = DateTime.Now.AddDays(-1).Date, * QTY = 37 * }, * new Stock() * { * Product = prods[1], * TimeStamp = DateTime.Now.Date, * QTY = 38 * }, * new Stock() * { * Product = prods[1], * TimeStamp = DateTime.Now.AddDays(-1).Date, * QTY = 42 * },*/ }; DateTime check = DateTime.Now.AddDays(-40).Date; Random rand = new Random(); do { foreach (var p in prods) { Stock stock = new Stock() { Product = p, TimeStamp = check.Date, QTY = (decimal)rand.NextDouble() * rand.Next(150) }; stock.Update(); snapshots.Add(stock); int i = rand.Next(6); for (var j = 0; j < i; j++) { Transaction t = new Transaction() { PayMethod = (PaymentType)rand.Next(3), }; int k = rand.Next(10); for (var l = 0; l < k; l++) { Sale s = new Sale() { Product = prods[rand.Next(prods.Count)], QTY = (decimal)rand.NextDouble() * rand.Next(10), GST = (rand.NextDouble() > 0.5) ? true : false, Void = false }; s.Price = s.Product.Price; s.Update(); Log log = new Log() { ProductID = s.Product.ID, QTY = -s.QTY, TimeStamp = t.SaleTime }; log.Update(); ctx.Logs.Add(log); t.Sales.Add(s); } t.Update(); t.SaleTime = check.AddMinutes(rand.Next(60 * 24)); ctx.Transactions.Add(t); } } check = check.AddDays(+1); } while (check.Date <= DateTime.Now.Date); ctx.StockSnapshot.AddRange(snapshots); // Save Transaction Database ctx.SaveChanges(); } }