public ActionResult Create([Bind(Include = "ProductId,Description,Name,ProductionStart")] Product product) { if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
public void InitializeCartWithKnownCustomerStoresValueInCustomerId() { //will add mocking later ... using (var separateContext = new OrderSystemContext()) { if (!separateContext.Customers.Any(c => c.CustomerCookie == "CustomerCookieABCDE")) { separateContext.Customers.Add(new Customer { CustomerCookie = "CustomerCookieABCDE", DateOfBirth = DateTime.Now, FirstName = "Julie", LastName = "Lerman" }); separateContext.SaveChanges(); } } var service = new WebSiteOrderingService(new WebSiteOrderData(_context)); SetupLogging(); RevisitedCart cart = service.ItemSelected(1, 1, 9.99m, theUri, "CustomerCookieABCDE", 0); WriteLog(); Assert.AreNotEqual(0, _context.Carts.Find(cart.CartId).CustomerId); }
static void Main(string[] args) { OrderSystemContext db = new OrderSystemContext(); #region 1.查询测试 //var products = db.ProductCatalogs.ToList(); #endregion #region 2.值对象测试 //Customer newCustomer = new Customer() { IDCardNumber = "120104198106072518", CustomerName = "Alex", Gender = "M", PhoneNumber = "test" }; //Address customerAddress = new Address { Country = "China", Province = "Tianjin", City = "Tianjin", StreetAddress = "Crown Plaza", ZipCode = "300308" }; //newCustomer.Address = customerAddress; //db.Customers.Add(newCustomer); //db.SaveChanges(); #endregion #region 添加一对多映射 Order order = new Order(); order.CreatedDate = DateTime.Now; order.Customer = db.Customers.FirstOrDefault(item => item.IDCardNumber == "rj"); OrderItem oi = new OrderItem(); oi.Order = order; oi.Products = db.Products.ToList(); order.OrderItems = new List <OrderItem>() { oi }; db.Orders.Add(order); try { int i = db.SaveChanges(); } catch (Exception ex) { } #endregion Console.ReadKey(); }
public int Complete() { // The number of objects written to the underlying database. return(context.SaveChanges()); }
public void AddOrder(Order order) { _dbContext.Add(Mapping.Map(order)); _dbContext.SaveChanges(); }
public void AddStore(Models.Location store) { _dbContext.Add(Mapping.Map(store)); _dbContext.SaveChanges(); }
public void Save() { _dbContext.SaveChanges(); }
public void AddCustomer(Models.Customer customer) { _dbContext.Add(Mapping.Map(customer)); _dbContext.SaveChanges(); }