public Customer Create(Customer customer)
        {
            var cust = _ctx.Customers.Add(customer).Entity;

            _ctx.SaveChanges();
            return(cust);
        }
Пример #2
0
        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));
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }
Пример #5
0
        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));
        }
Пример #6
0
        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));
        }
Пример #7
0
        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);
 }
Пример #10
0
 public void UpdateCustomer(Customers customer)
 {
     using (var customerContext = new CustomerAppContext())
     {
         customerContext.Customers.Update(customer);
         customerContext.SaveChanges();
     }
 }
Пример #11
0
 public void AddProduct(Products product)
 {
     using (var customerContext = new CustomerAppContext())
     {
         customerContext.Add(product);
         customerContext.SaveChanges();
     }
 }
Пример #12
0
 public void DeleteCustomer(int customerid)
 {
     using (var customerContext = new CustomerAppContext())
     {
         Customers customer = new Customers();
         customer.CustomerId = customerid;
         customerContext.Customers.Remove(customer);
         customerContext.SaveChanges();
     }
 }
Пример #13
0
        public Member Delete(int id)
        {
            var membRemoved = _context.Remove <Member>(new Member()
            {
                Id = id
            }).Entity;

            _context.SaveChanges();
            return(membRemoved);
        }
Пример #14
0
 public void AddCustomer(Customers customer)
 {
     using (var customerContext = new CustomerAppContext())
     {
         Random rand = new Random();
         customer.CustomerNumber = rand.Next();
         customerContext.Customers.Add(customer);
         customerContext.SaveChanges();
     }
 }
Пример #15
0
 public void DeleteProduct(int productid)
 {
     using (var customerContext = new CustomerAppContext())
     {
         Products product = new Products();
         product.ProductId = productid;
         customerContext.Remove(product.ProductId);
         customerContext.SaveChanges();
     }
 }
Пример #16
0
        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);
        }
Пример #19
0
 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);
 }
Пример #21
0
 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());
 }