public void Create(User entity) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } // Ensure the default location exists within the database if (entity.DefaultLocationId != null) { LocationRepository locationRepo = new LocationRepository(Database); // GetById will throw if location is invalid locationRepo.GetById((int)entity.DefaultLocationId); } Database.Add(entity); }
public void Create(Order entity) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } // Ensure the location and user of this // order are valid. (GetById will throw if not) LocationRepository locationRepo = new LocationRepository(Database); locationRepo.GetById(entity.LocationId); UserRepository userRepo = new UserRepository(Database); userRepo.GetById(entity.UserId); Database.Add(entity); }
public void Create(InventoryJunction entity) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } // Ensure the Location / Ingredient exist // before trying to create the junction // (GetById will throw if not) LocationRepository locationRepo = new LocationRepository(Database); locationRepo.GetById(entity.LocationId); IngredientRepository ingredientRepo = new IngredientRepository(Database); ingredientRepo.GetById(entity.IngredientId); // Location / Ingredients are valid. Can successfully create // the inventory junction Database.Add(entity); }
public LocationController(dbr.LocationRepository repo) { locationRepo = repo; }
public static void Initialize(PizzaStoreData.DataAccess.PizzaStoreDBContext database) { Database = database ?? throw new ArgumentNullException(nameof(database)); locationRepo = new dbr.LocationRepository(Database); }