Пример #1
0
 public Model.Stock AddStock(Model.Stock oldStock, Model.Location location, int quantity)
 {
     Entity.Stock updated = _context.Stocks.FirstOrDefault(stock => stock.Product == GetColor(oldStock.Product).Id&& stock.Location == location.Id);
     updated.Quantity = updated.Quantity + quantity;
     _context.SaveChanges();
     //_context.ChangeTracker.Clear();
     return(new Model.Stock(oldStock.Product, location, updated.Quantity));
 }
Пример #2
0
 public Model.Location GetLocation(Model.Location location)
 {
     Entity.Location found = _context.Locations.FirstOrDefault(loc => loc.City == location.City && loc.State == location.State);
     if (found == null)
     {
         return(null);
     }
     Entity.Customer foundManager = _context.Customers.FirstOrDefault(id => id.Id == found.Manager);
     return(new Model.Location(found.Id, found.City, found.State, new Model.Customer(foundManager.Name, foundManager.Username, foundManager.Password)));
 }
Пример #3
0
 public Model.Location AddLocation(Model.Location location)
 {
     _context.Locations.Add(
         new Entity.Location
     {
         City    = location.City,
         State   = location.State,
         Manager = GetUser(location.Manager).Id
     }
         );
     _context.SaveChanges();
     return(location);
 }
Пример #4
0
        public List <Model.Order> GetLocationOrders(Model.Location location, int sort)
        {
            List <Model.Order> orders = null;

            switch (sort)
            {
            case 1:
                orders = _context.Orders
                         .Where(ord => ord.Location == location.Id)
                         .OrderByDescending(x => x.Time)
                         .Select(
                    ord => new Model.Order(
                        ord.Id,
                        new Model.Customer(_context.Customers.FirstOrDefault(id => id.Id == ord.Customer).Name),
                        location,
                        ord.Total,
                        ord.Time)
                    ).ToList();
                break;

            case 2:
                orders = _context.Orders
                         .Where(ord => ord.Location == location.Id)
                         .OrderBy(x => x.Time)
                         .Select(
                    ord => new Model.Order(
                        ord.Id,
                        new Model.Customer(_context.Customers.FirstOrDefault(id => id.Id == ord.Customer).Name),
                        location,
                        ord.Total,
                        ord.Time)
                    ).ToList();
                break;

            case 3:
                orders = _context.Orders
                         .Where(ord => ord.Location == location.Id)
                         .OrderByDescending(x => x.Total)
                         .Select(
                    ord => new Model.Order(
                        ord.Id,
                        new Model.Customer(_context.Customers.FirstOrDefault(id => id.Id == ord.Customer).Name),
                        location,
                        ord.Total,
                        ord.Time)
                    ).ToList();
                break;

            case 4:
                orders = _context.Orders
                         .Where(ord => ord.Location == location.Id)
                         .OrderBy(x => x.Total)
                         .Select(
                    ord => new Model.Order(
                        ord.Id,
                        new Model.Customer(_context.Customers.FirstOrDefault(id => id.Id == ord.Customer).Name),
                        location,
                        ord.Total,
                        ord.Time)
                    ).ToList();
                break;

            default:
                break;
            }

            foreach (Order order in orders)
            {
                order.LineItems = _context.LineItems
                                  .Where(item => item.Orderid == order.Id)
                                  .Select(
                    item => new Model.LineItem(
                        order,
                        new Model.Product(_context.Products.FirstOrDefault(id => id.Id == item.Product).Name),
                        item.Quantity
                        )
                    ).ToList();
            }

            return(orders);
        }
Пример #5
0
 public Model.Location DeleteLocation(Model.Location location)
 {
     throw new System.NotImplementedException();
 }