Exemplo n.º 1
0
 public Model.Orders GetOrders(Model.Orders orders)
 {
     Entity.Order found = _context.Orders.FirstOrDefault(ord => ord.OrderId == orders.OrderId);
     if (found == null)
     {
         return(null);
     }
     return(new Model.Orders(found.OrderId, found.OrderQuantity, found.OrderNumber, found.OrderTotal, found.OrderLocation));
 }
Exemplo n.º 2
0
        // public Model.Products GetProducts(Model.Products products)
        // {
        //     Entity.Product found = _context.Products.FirstOrDefault(prod => prod.ProductId == products.ProductId);
        //     if(found == null) return null;
        //     return new Model.Products(found.ProductId, found.ProductName, found.ProductQuantity, found.ProductPrice);
        // }

        // public void UpdateProduct(Product product2BUpdated)
        // {
        //     Entity.Product oldProduct = _context.Products.Find(product2BUpdated.Id);
        //     _context.Entry(oldProduct).CurrentValues.SetValues(product2BUpdated);

        //     //Because I am not mapping the hero property in my mapper, i am unable to use the method
        //     //_context.Entry(oldSuperPower).CurrentValues.SetValues(_mapper.ParseSuperPower(hero2BUpdated.SuperPower))
        //     // this would throw an error because i have established a 1:1 relationship between my heroes and superpower
        //     //tables. Instead, I take advantage of the change tracker and use it to update the superpower
        //     Entity.Product oldProducts = _context.Productz.Find(product2BUpdated.Product.Id);
        //     oldProduct.productQuantity = product2BUpdated.productQuantity;

        //     _context.SaveChanges();

        //     //This method clears the change tracker to drop all tracked entities
        //     _context.ChangeTracker.Clear();
        // }
        // }

        public Model.Orders AddOrder(Model.Orders orders)
        {
            _context.Orders.Add(
                new Entity.Order {
                OrderId       = orders.OrderId,
                OrderQuantity = orders.OrderQuantity,
                OrderNumber   = orders.OrderNumber,
                OrderTotal    = orders.OrderTotal,
                OrderLocation = orders.OrderLocation,
                OrderDate     = DateTime.Now
            }
                );
            _context.SaveChanges();
            return(orders);
        }
Exemplo n.º 3
0
        public void UpdateOrder(Model.Orders order2BeUpdated)
        {
            Entity.Order oldOrder = _context.Orders.Find(order2BeUpdated.OrderId);

            _context.Entry(oldOrder).CurrentValues.SetValues(order2BeUpdated);


            Entity.Order oldOrder1 = _context.Orders.Find(order2BeUpdated.OrderId);


            oldOrder1.OrderQuantity = order2BeUpdated.OrderQuantity;

            oldOrder1.OrderTotal = order2BeUpdated.OrderTotal;

            _context.Entry(oldOrder).CurrentValues.SetValues((order2BeUpdated));


            _context.SaveChanges();

            // _context.ChangeTracker.Clear();
        }