コード例 #1
0
        /// <summary>
        /// Gets the location by a given name.
        /// </summary>
        /// <param name="name">The name of the location.</param>
        /// <returns>Returns the location with the given name.</returns>
        public async Task <Library.Model.ILocation> LookUpLocationByNameAsync(string name)
        {
            using var context = new DigitalStoreContext(Options);

            var storeLocation = await context.StoreLocations
                                .Include(s => s.Inventories)
                                .ThenInclude(i => i.Product)
                                .Include(s => s.Address)
                                .FirstOrDefaultAsync(s => s.Name == name);

            if (storeLocation is null)
            {
                return(null);
            }

            var inventoryPairs = storeLocation.Inventories.Select(
                i => new KeyValuePair <Library.Model.IProduct, int>(
                    new Library.Model.Product(i.Product.Name, i.Product.Category, i.Product.UnitPrice, i.ProductId),
                    i.Quantity)).ToList();

            var inventoryDictionary = inventoryPairs.ToDictionary((keyItem) => (keyItem).Key, (valueItem) => valueItem.Value);

            Library.Model.ILocation location = new Library.Model.Location(
                name: storeLocation.Name,
                address: storeLocation.Address.Print(),
                inventory: inventoryDictionary,
                id: storeLocation.Id
                );

            return(location);
        }
コード例 #2
0
        // order by time
        public IEnumerable <Library.Model.Order> GetLocationOrderHistory(Library.Model.Location location)
        {
            IQueryable <Entities.Order> orders = _dbContext.Orders
                                                 .Select(o => o)
                                                 .Where(o => o.LocationId == location.Id)
                                                 .OrderBy(o => o.TimePlaced)
                                                 .AsNoTracking();



            return(orders.Select(or => new Library.Model.Order
            {
                Id = or.Id,
                CustomerId = or.CustomerId,
                LocationId = or.LocationId,
                TimePlaced = or.TimePlaced,
                TotalPrice = or.TotalPrice,
                Products = or.OrderLines.Select(orl => orl.Product).Select(p => new Library.Model.Product
                {
                    Id = p.Id,
                    Name = p.Name,
                    Price = p.Price
                }).ToList(),
                ProductQuantities = or.OrderLines.Select(orl => orl.Quantity).ToList()
            }));
        }
コード例 #3
0
        public void Edit(Library.Model.Location model)
        {
            IQueryable <Location> locations = _locationContext.Locations
                                              .Include(l => l.InventoryLines)
                                              .ThenInclude(il => il.Product);
            Location entity = locations.First(l => l.LocationId == model.LocationId);

            if (entity == null)
            {
                s_logger.Warn($"Location to be edited does not exist: ignoring.");
                return;
            }
            foreach (Library.Model.InventoryLine line in model.Inventory)
            {
                InventoryLine entity2 = entity.InventoryLines.First(il => il.InventoryLineId == line.InventoryLineId);
                if (entity2 == null)
                {
                    s_logger.Warn($"InventoryLine to be edited on location ${entity.LocationId} does not exist: ignoring.");
                    return;
                }
            }

            s_logger.Info($"Editing Location");

            var products = _locationContext.Products
                           .AsNoTracking();

            foreach (Library.Model.InventoryLine line in model.Inventory)
            {
                InventoryLine entity2 = entity.InventoryLines.First(il => il.InventoryLineId == line.InventoryLineId);
                entity2.Quantity  = line.Quantity;
                entity2.LineTotal = entity2.Quantity * entity2.Product.UnitPrice;
                _locationContext.Update(entity2);
            }
            _locationContext.Update(entity);
        }
コード例 #4
0
 public void Delete(Library.Model.Location model)
 {
     throw new NotImplementedException();
 }