public Customer Create(Customer customer) { var cust = _ctx.Customers.Add(customer).Entity; _ctx.SaveChanges(); return(cust); }
public ActionResult Create([Bind(Include = "Id,Name,City,State,TotalSales")] Customer customer) { if (ModelState.IsValid) { db.Customers.Add(customer); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customer)); }
public Customer Create(Customer customer) { /*customer.Id = FakeDB.Id++; * FakeDB.Customers.Add(customer); * return customer; */ var cust = _ctx.Customers.Add(customer).Entity; _ctx.SaveChanges(); return(cust); }
public Customer Create(Customer customer) { if (customer.Type != null) { _ctx.Attach(customer.Type).State = EntityState.Unchanged; } var customerSaved = _ctx.Customers.Add(customer).Entity; _ctx.SaveChanges(); return(customerSaved); }
public ActionResult Create([Bind(Include = "Id,OrderId,Product,Quantity,Price")] OrderLine orderLine) { if (ModelState.IsValid) { db.OrderLines.Add(orderLine); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.OrderId = new SelectList(db.Orders, "Id", "Description", orderLine.OrderId); return(View(orderLine)); }
public ActionResult Create([Bind(Include = "Id,Description,Total,CustomerId")] Order order) { if (ModelState.IsValid) { db.Orders.Add(order); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CustomerId = new SelectList(db.Customers, "Id", "Name", order.CustomerId); return(View(order)); }
public Customer Create(Customer customer) { var cust = _ctx.Customers.Add(customer).Entity; _ctx.SaveChanges(); return(cust); //Old system /*customer.Id = id++; * FakeDB.Customers.Add(customer);//_customers.Add(customer); * return customer;*/ }
public Order Create(Order order) { var changeTracker = _ctx.ChangeTracker.Entries <Customer>(); if (order.Customer != null) { _ctx.Attach(order.Customer); } var saved = _ctx.Orders.Add(order).Entity; _ctx.SaveChanges(); return(saved); }
public Order Create(Order order) { /* if (order.Customer != null && * _ctx.ChangeTracker.Entries<Customer>() * .FirstOrDefault(ce => ce.Entity.ID == order.Customer.ID) == null) * { * _ctx.Attach(order.Customer); * } * var saved = _ctx.Orders.Add(order).Entity; * _ctx.SaveChanges(); * return saved;*/ _ctx.Attach(order).State = EntityState.Added; _ctx.SaveChanges(); return(order); }
public void UpdateCustomer(Customers customer) { using (var customerContext = new CustomerAppContext()) { customerContext.Customers.Update(customer); customerContext.SaveChanges(); } }
public void AddProduct(Products product) { using (var customerContext = new CustomerAppContext()) { customerContext.Add(product); customerContext.SaveChanges(); } }
public void DeleteCustomer(int customerid) { using (var customerContext = new CustomerAppContext()) { Customers customer = new Customers(); customer.CustomerId = customerid; customerContext.Customers.Remove(customer); customerContext.SaveChanges(); } }
public Member Delete(int id) { var membRemoved = _context.Remove <Member>(new Member() { Id = id }).Entity; _context.SaveChanges(); return(membRemoved); }
public void AddCustomer(Customers customer) { using (var customerContext = new CustomerAppContext()) { Random rand = new Random(); customer.CustomerNumber = rand.Next(); customerContext.Customers.Add(customer); customerContext.SaveChanges(); } }
public void DeleteProduct(int productid) { using (var customerContext = new CustomerAppContext()) { Products product = new Products(); product.ProductId = productid; customerContext.Remove(product.ProductId); customerContext.SaveChanges(); } }
public Order Create(Order order) { _ctx.Attach(order).State = EntityState.Added; _ctx.SaveChanges(); return(order); /* * // var changeTracker = _ctx.ChangeTracker.Entries<Customer>(); //very smart for debugging * if (order.Customer != null && * _ctx.ChangeTracker.Entries<Customer>() * .FirstOrDefault(ce => ce.Entity.Id == order.Customer.Id) == null) * { * //Attaches order to the given customer with the input ID (PostMan) * //instead of creating a new customer with that ID * _ctx.Attach(order.Customer); * } * var OrderSaved = _ctx.Orders.Add(order).Entity; * _ctx.SaveChanges(); * return OrderSaved; */ }
public Order Create(Order order) { /*if (order.Customer != null && * _ctx.ChangeTracker.Entries<Customer>() * .FirstOrDefault(ce => ce.Entity.Id == order.Customer.Id) == null) * { * _ctx.Attach(order.Customer); * } * order = _ctx.Add(order).Entity; * if (order.OrderLines != null) * { * foreach (var ol in order.OrderLines) * { * ol.OrderId = order.Id; * ol.ProductId = ol.ProductId; * _ctx.Add(ol); * } * } */ _ctx.Attach(order).State = EntityState.Added; _ctx.SaveChanges(); return(order); }
public User CreateUser(User user, string readablePassword) { if (string.IsNullOrEmpty(user.UserName)) { user.UserName = user.Email; } var hasher = new PasswordHasher <User>(); user.PasswordHash = hasher.HashPassword(user, readablePassword); //Getting Role from DB, to also get the roles name for use in TokenManager later user.Role = _ctx.Roles.FirstOrDefault(r => r.Id == user.Role.Id); var savedUser = _ctx.Users.Add(user).Entity; _ctx.SaveChanges(); return(savedUser); }
public int Complete() { //The number of objects written to the underlying database. return(context.SaveChanges()); }
public Product Create(Product product) { _ctx.Attach(product).State = EntityState.Added; _ctx.SaveChanges(); return(product); }
public int complete() { // int return the number of objects underlined modified in database return(_context.SaveChanges()); }
public void Add(User entity) { db.Users.Add(entity); db.SaveChanges(); }
public int Complete() { return(context.SaveChanges()); }