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