//Translate data model object to BDO. private void Translate_DTO_to_BDO(Inventory_BDO inventory_BDO, DataModel.Inventory inventory_dto) { inventory_BDO.ID = inventory_dto.Inventory_ID; inventory_BDO.Products_ID = inventory_dto.Product_ID; inventory_BDO.Quantity = inventory_dto.Product_Quantity; inventory_BDO.Warehouse_ID = inventory_dto.Warehouse_ID; }
/// <summary> /// MSCS 701-702 Topics in Math Sts, & Comp Sci /// Service Oriented Architecture (SOA) /// Spring 2019 /// Omar Waller /// /// Description: This class contains CRUD and Get queries to the Inventory table in the Warehouse database configured /// in the app.config file. /// </summary> // This method creates a Inventory record in the Warehouse database and returns true if the operation was successful. public bool Create(DataModel.Inventory inventory, ref string msg) { using (var context = new DataModel.WarehouseContext()) { // Create and save a new Products DataModel.Inventory newInventory = new DataModel.Inventory(); bool success = false; newInventory.Product_Quantity = inventory.Product_Quantity; newInventory.Inventory_ID = inventory.Inventory_ID; newInventory.Product_ID = inventory.Product_ID; newInventory.Warehouse_ID = inventory.Warehouse_ID; context.Inventories.Add(newInventory); //Check execution of transaction - we expect 1 change to have occurred var execution_result = context.SaveChanges(); if (execution_result != 1) { msg = "Inventory not created in DB - DAL"; } else { msg = "Inventory object successfully created."; success = true; } return(success); } }
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(); }