public static void CreateHouses(IServiceProvider serviceProvider) { using (var context = new HouseDbContext( serviceProvider.GetRequiredService <DbContextOptions <HouseDbContext> >())) { if (!context.House.Any()) { context.House.AddRange( new House { Zip = "91202", }, new House { Zip = "91203", }, new House { Zip = "91204", } ); context.SaveChanges(); } } }
public List <House> GetAllHousesByPostal(string postalCode) { using var db = new HouseDbContext(); var houses = db.Houses.Where(x => x.PostalCode == postalCode).ToList(); return(houses); }
public House GetHouse(int houseId) { using var db = new HouseDbContext(); var house = db.Houses.FirstOrDefault(x => x.Id == houseId); return(house); }
public void DeleteHouseById(int houseId) { using var db = new HouseDbContext(); var houseToDelete = db.Houses.Find(houseId); db.Houses.Remove(houseToDelete); db.SaveChanges(); }
public House UpdateHouse(int houseIdToEdit, House UpdatehouseValues) { using var db = new HouseDbContext(); var HouseToEdit = db.Houses.First(house => house.Id == houseIdToEdit); HouseToEdit.StreetName = UpdatehouseValues.StreetName; HouseToEdit.HouseNumber = UpdatehouseValues.HouseNumber; HouseToEdit.PostalCode = UpdatehouseValues.PostalCode; HouseToEdit.City = UpdatehouseValues.City; HouseToEdit.Persons = UpdatehouseValues.Persons; db.SaveChanges(); return(HouseToEdit); }
public AjaxController(HouseDbContext context) { _context = context; }
public ContactController(HouseDbContext context) { _context = context; }
public ProjectsController(HouseDbContext context) { _context = context; }
public HomeController(HouseDbContext context) { _context = context; }
public WhatWeDoController(HouseDbContext context) { _context = context; }
public void CreateHouse(House Newhouse) { using var db = new HouseDbContext(); db.Add(Newhouse); db.SaveChanges(); }