public void Seed() { _ctx.Database.EnsureCreated(); if (!_ctx.Products.Any()) { var filePath = Path.Combine(_hosting.ContentRootPath, "Data/art.json"); var json = File.ReadAllText(filePath); var products = JsonConvert.DeserializeObject <IEnumerable <Product> >(json); _ctx.Products.AddRange(products); var order = new Order() { OrderDate = DateTime.Now, OrderNumber = "12345", Items = new List <OrderItem> { new OrderItem { Product = products.First(), Quantity = 5, UnitPrice = products.First().Price } } }; _ctx.Orders.Add(order); _ctx.SaveChanges(); } }
public IActionResult NewActivity(Activities newActive) { int?uid = HttpContext.Session.GetInt32("uid"); if (uid is null) { return(RedirectToAction("Index", "LogReg")); } if (ModelState.IsValid) { int?id = HttpContext.Session.GetInt32("uid"); newActive.Coordinator = (int)id; dbContext.Add(newActive); dbContext.SaveChanges(); return(RedirectToAction("Dashboard")); } else { return(View("CreateActivity")); } }