示例#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();
 }
 // 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));
 }
 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);
 }
 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
            });
        }
 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();
 }