Пример #1
0
        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();
                }
            }
        }
Пример #2
0
        public List <House> GetAllHousesByPostal(string postalCode)
        {
            using var db = new HouseDbContext();
            var houses = db.Houses.Where(x => x.PostalCode == postalCode).ToList();

            return(houses);
        }
Пример #3
0
        public House GetHouse(int houseId)
        {
            using var db = new HouseDbContext();
            var house = db.Houses.FirstOrDefault(x => x.Id == houseId);

            return(house);
        }
Пример #4
0
        public void DeleteHouseById(int houseId)
        {
            using var db = new HouseDbContext();
            var houseToDelete = db.Houses.Find(houseId);

            db.Houses.Remove(houseToDelete);
            db.SaveChanges();
        }
Пример #5
0
        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);
        }
Пример #6
0
 public AjaxController(HouseDbContext context)
 {
     _context = context;
 }
Пример #7
0
 public ContactController(HouseDbContext context)
 {
     _context = context;
 }
Пример #8
0
 public ProjectsController(HouseDbContext context)
 {
     _context = context;
 }
Пример #9
0
 public HomeController(HouseDbContext context)
 {
     _context = context;
 }
Пример #10
0
 public WhatWeDoController(HouseDbContext context)
 {
     _context = context;
 }
Пример #11
0
 public void CreateHouse(House Newhouse)
 {
     using var db = new HouseDbContext();
     db.Add(Newhouse);
     db.SaveChanges();
 }