Пример #1
0
        public Model.Order AddOrder(Model.Order newOrder, Model.Location location)
        {
            Entity.Order DBOrder = new Entity.Order {
                Cusername  = newOrder.Customer.UserName,
                LocationId = location.LocationID,
                Orderdate  = newOrder.Orderdate,
                Total      = newOrder.Total
            };
            _context.Orders.Add(DBOrder);
            _context.SaveChanges();

            List <Model.Item> items = newOrder.Items;

            foreach (Model.Item item in items)
            {
                _context.Items.Add(
                    new Entity.Item {
                    LocationId  = DBOrder.LocationId,
                    OrderId     = DBOrder.OrderId,
                    ProductName = item.Product.ProductName,
                    Price       = item.Product.Price,
                    Quantity    = item.Quantity
                }
                    );
                changeInventory(location, item, -1 * item.Quantity);
            }
            _context.SaveChanges();
            return(newOrder);
        }
Пример #2
0
 public void UpdateLocationInventory(Models.Location location, Models.Product product, int delta)
 {
     Entities.Inventory i = ctx.Inventories.Where(i => i.LocationId == location.LocationID && i.ProductId == product.ProductID).ToList().FirstOrDefault();
     if (i == null)
     {
         i = new Entities.Inventory();
         if (location.LocationID != null)
         {
             i.LocationId = (int)location.LocationID;
         }
         if (product.ProductID != null)
         {
             i.ProductId = (int)product.ProductID;
         }
         i.Quantity = 0;
         ctx.Inventories.Add(i);
     }
     i.Quantity += delta;
     if (i.Quantity < 0)
     {
         throw new Exception("Tried to set inventory quantity to " + i.Quantity);
     }
     else if (i.Quantity == 0)
     {
         ctx.Inventories.Remove(i);
     }
     using var log = new LoggerConfiguration()
                     .WriteTo.File("log.txt", rollingInterval: RollingInterval.Day, shared: true)
                     .CreateLogger();
     log.Information("TRANSACTION: Updated inventory");
     ctx.SaveChanges();
 }
Пример #3
0
 // public Models.Inventory ParseInventory(Entities.Inventory inventory) {
 //     return new Models.Inventory();
 // }
 // public Entities.Inventory ParseInventory(Models.Inventory inventory) {
 //     return new Entities.Inventory();
 // }
 public Models.Location ParseLocation(Entities.Location location)
 {
     Models.Location loc = new Models.Location();
     loc.LocationID   = location.LocationId;
     loc.LocationName = location.LocationName;
     loc.Address      = location.LocationAddress;
     return(loc);
 }
Пример #4
0
 public Inventory UpdateInventory(Model.Inventory inventory, Model.Location location, Model.Product product)
 {
     Entity.Inventory updateInventory = _context.Inventories.Single(inven => inven.InventoryId == inventory.Id);
     updateInventory.Quantity = inventory.Quantity;
     _context.SaveChanges();
     Log.Information("DL persisted inventory update to DB");
     return(inventory);
 }
Пример #5
0
 public Model.Order UpdateOrder(Model.Order order, Model.Location location, Model.Customer customer)
 {
     Entity.Order updateOrder = _context.Orders.Single(ord => ord.OrderId == order.OrderID);
     updateOrder.Total = order.Total;
     _context.SaveChanges();
     Log.Information("DL persisted order update to DB");
     return(order);
 }
Пример #6
0
        public void changeInventory(Model.Location location, Model.Item item, int amount)
        {
            Entity.Item Eitem = _context.Items.
                                FirstOrDefault(itm => itm.OrderId == null && itm.LocationId == location.LocationID && itm.ProductName == item.Product.ProductName);

            Eitem.Quantity += amount;

            _context.SaveChanges();
        }
Пример #7
0
 public Entity.Location ParseLocation(Model.Location location)
 {
     return(new Entity.Location
     {
         Address = location.Address,
         State = location.State,
         LocationName = location.LocationName
     });
 }
        public Model.Location AddNewLocation(Model.Location loc)
        {
            Entity.StoreFront locToAdd = _context.StoreFronts
                                         .Add(_mapper.ParseStore(loc, true)).Entity;

            _context.SaveChanges();
            _context.ChangeTracker.Clear();
            return(_mapper.ParseStore(locToAdd));
        }
Пример #9
0
 public Model.Location GetLocation(Model.Location location)
 {
     Entity.Location found = _context.Locations.FirstOrDefault(loca => loca.StoreName == location.StoreName && loca.Address == location.Address && loca.City == location.City && loca.State == location.State);
     if (found == null)
     {
         return(null);
     }
     Log.Information("DL sent location to BL");
     return(new Model.Location(found.LocationId, found.StoreName, found.Address, found.City, found.State));
 }
Пример #10
0
 public void GetLocationByName()
 {
     using (var context = new Entity.StoreAppDBContext(options))
     {
         IRepository    _repo  = new RepoDB(context);
         Model.Location result = _repo.GetLocation("WA-Seattle");
         Assert.NotNull(result);
         Assert.Equal(1, result.Id);
     }
 }
Пример #11
0
 public Entities.Location ParseLocation(Models.Location location)
 {
     Entities.Location loc = new Entities.Location();
     if (location.LocationID != null)
     {
         loc.LocationId = (int)location.LocationID;
     }
     loc.LocationName    = location.LocationName;
     loc.LocationAddress = location.Address;
     return(loc);
 }
Пример #12
0
 public void GetAllInventories()
 {
     using (var context = new Entity.StoreAppDBContext(options))
     {
         IRepository          _repo    = new RepoDB(context);
         Model.Location       location = _repo.GetLocation("WA-Seattle");
         HashSet <Model.Item> result   = _repo.GetAllInventories(location);
         Assert.NotNull(result);
         Assert.Equal(1, result.Count);
     }
 }
Пример #13
0
        public Model.Location AddLocation(Model.Location location)
        {
            _context.Locations.Add(
                new Entity.Location {
                LocationName    = location.LocationName,
                LocationAddress = location.Address
            }
                );

            _context.SaveChanges();
            return(location);
        }
Пример #14
0
        public List <Model.Item> GetInventory(Model.Location location)
        {
            Entity.Location found = _context.Locations.FirstOrDefault(local => local.LocationName == location.LocationName && local.LocationAddress == location.Address);

            List <Model.Item> items = _context.Items.Where(
                item => item.LocationId == found.LocationId && item.OrderId == null)
                                      .Select(
                item => new Model.Item(new Model.Product(item.ProductName, (double)item.Price), (int)item.Quantity)
                ).ToList();

            return(items);
        }
Пример #15
0
        public Model.Location GetLocation(Model.Location location)
        {
            Entity.Location found = _context.Locations.FirstOrDefault(local => local.LocationName == location.LocationName && local.LocationAddress == location.Address);

            if (found == null)
            {
                return(null);
            }
            else
            {
                return(new Model.Location(found.LocationName, found.LocationAddress, found.LocationId));
            }
        }
Пример #16
0
 public Model.Item AddItemToLocation(Model.Location location, Model.Item item)
 {
     _context.Items.Add(
         new Entity.Item {
         LocationId  = location.LocationID,
         OrderId     = null,
         ProductName = item.Product.ProductName,
         Price       = item.Product.Price,
         Quantity    = item.Quantity
     }
         );
     _context.SaveChanges();
     return(item);
 }
Пример #17
0
 public Model.Order AddOrder(Model.Order order, Model.Location location, Model.Customer customer)
 {
     _context.Orders.Add(
         new Entity.Order {
         LocationId = order.LocationID,
         CustomerId = order.CustomerID,
         Total      = order.Total,
         OrderDate  = order.OrderDate
     }
         );
     Log.Information("DL persisted order add to DB");
     _context.SaveChanges();
     return(order);
 }
Пример #18
0
 public Model.Location AddLocation(Model.Location location)
 {
     _context.Locations.Add(
         new Entity.Location {
         StoreName = location.StoreName,
         Address   = location.Address,
         City      = location.City,
         State     = location.State
     }
         );
     Log.Information("DL persisted location add to DB");
     _context.SaveChanges();
     return(location);
 }
Пример #19
0
 public Model.Inventory AddInventory(Model.Inventory inventory, Model.Location location, Model.Product product)
 {
     _context.Inventories.Add(
         new Entity.Inventory {
         InventoryId = inventory.Id,
         LocationId  = GetLocation(location).Id,
         ProductId   = GetProduct(product).Id,
         Quantity    = inventory.Quantity
     }
         );
     _context.SaveChanges();
     Log.Information("DL persisted inventory add to DB");
     return(inventory);
 }
Пример #20
0
 public Entity.Location ParseLocation(Model.Location location)
 {
     if (location.LocationID == null)
     {
         return(new Entity.Location
         {
             LocationName = location.LocationName,
             LocationAddress = location.LocationAddress
         });
     }
     return(new Entity.Location
     {
         LocationName = location.LocationName,
         LocationAddress = location.LocationAddress,
         Id = (int)location.LocationID
     });
 }
Пример #21
0
        public Entity.StoreFront ToEntity(Model.Location location)
        {
            List <Entity.Inventory> inventories = new List <Entity.Inventory>();

            if (location.Inventory is not null)
            {
                foreach (Model.Inventory inven in location.Inventory)
                {
                    inventories.Add(ToEntity(inven));
                }
            }
            return(new Entity.StoreFront {
                Id = location.Id,
                SName = location.Name,
                SAddress = location.Address,
                Inventories = inventories
            });
        }
Пример #22
0
        public List <Model.Order> LocationOrdersByTotal(Model.Location location)
        {
            List <Model.Order> allOrders     = GetAllOrder();
            List <Model.Order> locationOrder = new List <Model.Order>();

            foreach (Model.Order order in allOrders)
            {
                if (order.Location.LocationID == location.LocationID)
                {
                    locationOrder.Add(order);
                }
            }

            locationOrder.Sort(delegate(Model.Order x, Model.Order y)
            {
                return(x.Total.CompareTo(y.Total));
            });

            return(locationOrder);
        }
Пример #23
0
        public Entity.Location ParseLocation(Model.Location location)
        {
            if (location.Id == null)
            {
                return(new Entity.Location
                {
                    LocName = location.LocName,
                    LocPhone = location.LocPhone,
                    LocAddress = location.LocAddress,
                    //Inventory = ParseInventory(location.Inventory)
                });
            }

            return(new Entity.Location
            {
                LocName = location.LocName,
                LocPhone = location.LocPhone,
                LocAddress = location.LocAddress,
                //Inventory = ParseInventory(location.Inventory),
                Id = (int)location.Id
            });
        }
Пример #24
0
 public Entity.Location ParseLocation(Model.Location location)
 {
     //when there are no locations, NO id is set
     if (location.Id == 0)
     {
         return(new Entity.Location
         {
             Address = location.Address,
             City = location.City,
             State = location.State,
             Zipcode = location.Zipcode
         });
     }
     //for updating and deleting
     return(new Entity.Location
     {
         Address = location.Address,
         City = location.City,
         State = location.State,
         Zipcode = location.Zipcode,
         Id = location.Id
     });
 }
 public Entity.StoreFront ParseStore(Model.Location store, bool create)
 {
     if (store is null)
     {
         return(null);
     }
     if (create)
     {
         return(new Entity.StoreFront
         {
             SName = store.Name,
             SAddress = store.Address
         });
     }
     else
     {
         return(new Entity.StoreFront
         {
             Id = store.Id,
             SName = store.Name,
             SAddress = store.Address
         });
     }
 }
Пример #26
0
 public List <Models.Product> GetAvailableProducts(Models.Location location)
 {
     return(ctx.Inventories.Include(i => i.Product).Where(i => i.LocationId == location.LocationID).Select(i => mapper.ParseProduct(i.Product)).ToList());
 }
Пример #27
0
 public Model.Location ParseLocation(Entity.Location location)
 {
     Model.Location newLocation = new Model.Location(location.Address, location.State, location.LocationName);
     newLocation.LocationID = location.LocationId;
     return(newLocation);
 }
Пример #28
0
 public Model.Location AddLocation(Model.Location newLocation)
 {
     _context.Locations.Add(_mapper.ParseLocation(newLocation));
     _context.SaveChanges();
     return(newLocation);
 }
Пример #29
0
 public int GetLocationInventory(Models.Location location, Models.Product product)
 {
     return(ctx.Inventories.Where(i => i.LocationId == location.LocationID && i.ProductId == product.ProductID).Select(i => i.Quantity).ToList().FirstOrDefault());
 }
Пример #30
0
 public Entity.Location ParseLocations(Model.Location location)
 {
     throw new System.NotImplementedException();
 }