Ejemplo n.º 1
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);
        }
 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);
 }
Ejemplo n.º 3
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)
        {
            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);
             * }
             * 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 Product Create(Product product)
 {
     _ctx.Attach(product).State = EntityState.Added;
     _ctx.SaveChanges();
     return(product);
 }
Ejemplo n.º 7
0
 //For some reason, update not functioning propperly atm.
 public Customer Update(Customer customerUpdate)
 {
     _ctx.Attach(customerUpdate).State = EntityState.Modified;
     _ctx.SaveChanges();
     return(customerUpdate);
 }
Ejemplo n.º 8
0
 public Fine Create(Fine fine)
 {
     _context.Attach(fine).State = Microsoft.EntityFrameworkCore.EntityState.Added;
     _context.SaveChangesAsync();
     return(fine);
 }