示例#1
0
        // Meant to be used to subtract the quantity of the animal from a processed order
        // Not using Library.order object directly since I want the option to remove from inventory even without a new order subtraction
        public void RemoveFromInventoryDb(int storeid, Library.Animal animal, int quantity)
        {
            using var context = new AquariumContext(_contextOptions);
            var dbInventory = context.Inventories
                              .Where(i => i.StoreId == storeid)
                              .Where(i => i.AnimalId == animal.AnimalId)
                              .FirstOrDefault();

            dbInventory.Quantity -= quantity;
            context.SaveChanges();
        }
示例#2
0
        public void UpdateAnimalDb(Library.Animal animal)
        {
            using var context = new AquariumContext(_contextOptions);
            var dbAnimal = context.Animals
                           .Where(a => a.AnimalId == animal.AnimalId)
                           .FirstOrDefault();

            dbAnimal.Name  = animal.Name;
            dbAnimal.Price = animal.Price;
            context.SaveChanges();
        }
示例#3
0
        public void UpdateInventoryDb(string city, Library.Animal animal, int stock)
        {
            using var context = new AquariumContext(_contextOptions);
            var currentStore = GetStoreByCity(city);
            var dbInventory  = context.Inventories
                               .Include(i => i.Animal)
                               .Where(i => i.StoreId == currentStore.StoreId && i.Animal.Name == animal.Name)
                               .FirstOrDefault();

            dbInventory.Quantity += stock;
            context.SaveChanges();
        }
示例#4
0
        // Creates a new animal. All animal repository methods are optional
        public void AddToAnimalDb(Library.Animal animal)
        {
            using var context = new AquariumContext(_contextOptions);
            var newEntry = new DataModel.Animal
            {
                Name  = animal.Name,
                Price = animal.Price
            };

            context.Animals.Add(newEntry);
            context.SaveChanges();
        }
示例#5
0
        public void UpdateCustomerDb(Library.Customer customer)
        {
            using var context = new AquariumContext(_contextOptions);
            var dbCust = context.Customers
                         .Where(c => c.CustomerId == customer.CustomerId)
                         .FirstOrDefault();

            dbCust.FirstName = customer.FirstName;
            dbCust.LastName  = customer.LastName;
            dbCust.Email     = customer.Email;
            context.SaveChanges();
        }
示例#6
0
        public void AddToCustomerDb(Library.Customer customer)
        {
            using var context = new AquariumContext(_contextOptions);
            var newCust = new DataModel.Customer()
            {
                FirstName = customer.FirstName,
                LastName  = customer.LastName,
                Email     = customer.Email
            };

            context.Customers.Add(newCust);
            context.SaveChanges();
        }
示例#7
0
        public void AddToInventoryDb(string city, Library.Animal animal, int stock)
        {
            using var context = new AquariumContext(_contextOptions);
            var currentStore  = GetStoreByCity(city);
            var currentAnimal = GetAnimalByName(animal.Name);
            var newEntry      = new DataModel.Inventory()
            {
                StoreId  = currentStore.StoreId,
                AnimalId = currentAnimal.AnimalId,
                Quantity = stock
            };

            context.Inventories.Add(newEntry);
            context.SaveChanges();
        }
示例#8
0
        public void UpdateOrderDb(Library.Order order)
        {
            using var context = new AquariumContext(_contextOptions);
            var dbOrders = context.Orders
                           .Where(o => o.OrderId == order.OrderId)
                           .FirstOrDefault();

            dbOrders.StoreId    = order.StoreId;
            dbOrders.CustomerId = order.Customer.CustomerId;
            dbOrders.Date       = order.Date;
            dbOrders.AnimalId   = order.Animal.AnimalId;
            dbOrders.Quantity   = order.Quantity;
            dbOrders.Total      = order.Total;
            context.SaveChanges();
        }
示例#9
0
        public void AddToOrderDb(Library.Order order)
        {
            using var context = new AquariumContext(_contextOptions);
            var newEntry = new DataModel.Order
            {
                StoreId    = order.StoreId,
                CustomerId = order.Customer.CustomerId,
                AnimalId   = order.Animal.AnimalId,
                Quantity   = order.Quantity,
                Total      = order.Total,
                Date       = order.Date
            };

            context.Orders.Add(newEntry);
            context.SaveChanges();
        }