コード例 #1
0
    public IActionResult Post([FromBody] Contract contract)
    {
        var newContract = db.Contracts.Add(contract);

        db.SaveChanges();
        return(CreatedAtRoute("GetContract", new { id = contract.Id }, contract));
    }
コード例 #2
0
    public IActionResult Post([FromBody] Rental rental)
    {
        var newRental = db.Rentals.Add(rental);

        db.SaveChanges();
        return(CreatedAtRoute("GetRental", new { id = rental.Id }, rental));
    }
コード例 #3
0
ファイル: HolidayhomeDAL.cs プロジェクト: DERESICL/Code
        public bool updateHolidayhomeDb(Holidayhome hse)
        {
            db.Entry(hse).State = EntityState.Modified;

            db.SaveChanges();
            return(true);
        }
コード例 #4
0
    public IActionResult Post([FromBody] Sale sale)
    {
        var newSale = db.Sales.Add(sale);

        db.SaveChanges();
        return(CreatedAtRoute("GetSale", new { id = sale.Id }, sale));
    }
コード例 #5
0
        public ActionResult <Advert> AddAdvert(Advert advert)
        {
            _advertContext.Adverts.Add(advert);
            _advertContext.SaveChanges();

            return(advert);
        }
コード例 #6
0
        public UserModel AddUser(User user)
        {
            _userContext.Add(user);
            _userContext.SaveChanges();
            var userModel = Map(user);

            return(userModel);
        }
コード例 #7
0
        public void Delete(T entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            Entities.Remove(entity);
            context.SaveChanges();
        }
コード例 #8
0
        public ActionResult Create(Holidayhome holidayhome)
        {
            if (ModelState.IsValid)
            {
                db.Holidayhomes.Add(holidayhome);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(holidayhome));
        }
コード例 #9
0
ファイル: OwnerController.cs プロジェクト: DERESICL/Code
        public ActionResult Create(Owner owner)
        {
            if (ModelState.IsValid)
            {
                db.Owners.Add(owner);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(owner));
        }
コード例 #10
0
ファイル: HolidayhomeDAL.cs プロジェクト: DERESICL/Code
 public bool updateHolidayhomeDb(Holidayhome hse)
 {
     db.Entry(hse).State = EntityState.Modified;
     try
     {
         db.SaveChanges();
         return(true);
     }
     catch (Exception exp)
     {
         // do something
         return(false);
     }
 }
コード例 #11
0
        public void Setup()
        {
            InitialiseMapping();

            _connection = new SqliteConnection("DataSource=:memory:");
            _connection.Open();

            var options = new DbContextOptionsBuilder <PropertyContext>()
                          .UseSqlite(_connection)
                          .Options;

            var inMemoryContext = new PropertyContext(options);

            inMemoryContext.Properties.AddRange(GenerateFakeProperties());
            inMemoryContext.SaveChanges();

            // While working with a inMemoryDb there is no need for mocking IPropertyRepository
            // Instead working to implementation provides implementation test without affecting Db

            // var service = new Mock<IPropertyRepository>();
            // service.Setup(p => p.GetProperties()).Returns(inMemoryContext.Properties);
            var service = new PropertyRepository(inMemoryContext);

            Sut = new PropertiesController(service);
        }
コード例 #12
0
        protected void AddDummyData(DbContextOptions <PropertyContext> contextOptions)
        {
            var ctx = new PropertyContext(contextOptions);

            ctx.Properties.AddRangeAsync(GetDummyDataItems());
            ctx.SaveChanges();
        }
コード例 #13
0
ファイル: PropertyController.cs プロジェクト: hgouw/Test
 public ActionResult Edit(Property property)
 {
     if (ModelState.IsValid)
     {
         var propertyContext = new PropertyContext();
         propertyContext.Properties.Add(property);
         propertyContext.SaveChanges();
         return(RedirectToAction("List"));
     }
     return(View());
 }
コード例 #14
0
        public void Setup()
        {
            InitialiseMapping();

            _connection = new SqliteConnection("DataSource=:memory:");
            _connection.Open();

            var options = new DbContextOptionsBuilder <PropertyContext>()
                          .UseSqlite(_connection)
                          .Options;

            var inMemoryContext = new PropertyContext(options);

            inMemoryContext.Properties.AddRange(GenerateFakeProperties());
            inMemoryContext.SaveChanges();

            Sut = new PropertyRepository(inMemoryContext);
        }
コード例 #15
0
        public ActionResult Index()
        {
            ViewBag.Message = "Adding Data to Database...";
            using (var db = new PropertyContext())
            {
                var prop1 = new Property();
                prop1.Id       = 1;
                prop1.Name     = "Monokatoikia";
                prop1.Location = "Drama";
                prop1.Price    = "300.000$";

                var prop2 = new Property();
                prop2.Id       = 2;
                prop2.Name     = "Diamerisma";
                prop2.Location = "Kavala";
                prop2.Price    = "199.000$";

                db.Properties.Add(prop1);
                db.Properties.Add(prop2);
                db.SaveChanges();
            }
            return(View());
        }
コード例 #16
0
 public void Save()
 {
     context.SaveChanges();
 }
コード例 #17
0
ファイル: BookingDAL.cs プロジェクト: DERESICL/Code
 public bool updateBookingDb(Booking bok)
 {
     db.Entry(bok).State = EntityState.Modified;
     db.SaveChanges();
     return(true);
 }
コード例 #18
0
 public static void Initialize(IServiceProvider serviceProvider)
 {
     using (var context = new PropertyContext(
                serviceProvider.GetRequiredService <DbContextOptions <PropertyContext> >())
            )
     {
         if (context.Property.Any())
         {
             return; // DB has been seeded with data
         }
         context.Property.AddRange(
             new Property
         {
             Price          = 350000,
             Address        = "12343 Kingsley St",
             City           = "Dearborn",
             Zip            = 48126,
             YearBuilt      = 2020,
             PropertyType   = "single",
             SquareFeet     = 2500,
             Bedrooms       = 5,
             Bathrooms      = 3,
             GarageCapacity = 2,
             RelatorName    = "Moe Zhar",
             RelatorPhone   = "313-989-2344",
             RelatorEmail   = "*****@*****.**"
         },
             new Property
         {
             Price          = 255000,
             Address        = "4423 Joanthan St",
             City           = "Dearborn",
             Zip            = 48126,
             YearBuilt      = 1989,
             PropertyType   = "town home",
             SquareFeet     = 1600,
             Bedrooms       = 3,
             Bathrooms      = 2,
             GarageCapacity = 1,
             RelatorName    = "Moe Zhar",
             RelatorPhone   = "313-989-2344",
             RelatorEmail   = "*****@*****.**"
         },
             new Property
         {
             Price          = 199000,
             Address        = "4555 Maple St",
             City           = "Dearborn Heights",
             Zip            = 48127,
             YearBuilt      = 1938,
             PropertyType   = "single",
             SquareFeet     = 1982,
             Bedrooms       = 4,
             Bathrooms      = 2,
             GarageCapacity = 1.5,
             RelatorName    = "Moe Zhar",
             RelatorPhone   = "313-989-2344",
             RelatorEmail   = "*****@*****.**"
         },
             new Property
         {
             Price          = 848000,
             Address        = "2342 Reuter St",
             City           = "Canton",
             Zip            = 48129,
             YearBuilt      = 2021,
             PropertyType   = "single",
             SquareFeet     = 4800,
             Bedrooms       = 8,
             Bathrooms      = 4,
             GarageCapacity = 2.5,
             RelatorName    = "Ali Shami",
             RelatorPhone   = "248-999-4543",
             RelatorEmail   = "*****@*****.**"
         },
             new Property
         {
             Price          = 155000,
             Address        = "4242 Westland St",
             City           = "Dearborn Heights",
             Zip            = 48127,
             YearBuilt      = 1992,
             PropertyType   = "town home",
             SquareFeet     = 1052,
             Bedrooms       = 3,
             Bathrooms      = 1.5,
             GarageCapacity = 1,
             RelatorName    = "Ali Shami",
             RelatorPhone   = "248-999-4543",
             RelatorEmail   = "*****@*****.**"
         },
             new Property
         {
             Price          = 1000000,
             Address        = "1232 Trump St",
             City           = "West Bloomfield",
             Zip            = 24012,
             YearBuilt      = 2019,
             PropertyType   = "Single",
             SquareFeet     = 8000,
             Bedrooms       = 10,
             Bathrooms      = 4,
             GarageCapacity = 3,
             RelatorName    = "Ali Shami",
             RelatorPhone   = "248-999-4543",
             RelatorEmail   = "*****@*****.**"
         },
             new Property
         {
             Price          = 100000,
             Address        = "2323 Emanon St",
             City           = "Dearborn",
             Zip            = 48126,
             YearBuilt      = 1995,
             PropertyType   = "condo",
             SquareFeet     = 968,
             Bedrooms       = 2,
             Bathrooms      = 1,
             GarageCapacity = 0,
             RelatorName    = "Ahmed Abdofara",
             RelatorPhone   = "734-355-2424",
             RelatorEmail   = "*****@*****.**"
         },
             new Property
         {
             Price          = 50000,
             Address        = "7323 Bingham St",
             City           = "Detroit",
             Zip            = 48125,
             YearBuilt      = 1933,
             PropertyType   = "condo",
             SquareFeet     = 750,
             Bedrooms       = 1,
             Bathrooms      = 1,
             GarageCapacity = 1,
             RelatorName    = "Ahmed Abdofara",
             RelatorPhone   = "734-355-2424",
             RelatorEmail   = "*****@*****.**"
         },
             new Property
         {
             Price          = 392000,
             Address        = "7242 Kingsley St",
             City           = "Dearborn",
             Zip            = 48126,
             YearBuilt      = 2001,
             PropertyType   = "single",
             SquareFeet     = 2252,
             Bedrooms       = 4,
             Bathrooms      = 2,
             GarageCapacity = 1,
             RelatorName    = "Zeinab Dabaj",
             RelatorPhone   = "248-999-2323",
             RelatorEmail   = "*****@*****.**"
         },
             new Property
         {
             Price          = 340000,
             Address        = "7744 Middlesex St",
             City           = "Livonia",
             Zip            = 48122,
             YearBuilt      = 1998,
             PropertyType   = "town home",
             SquareFeet     = 1900,
             Bedrooms       = 3,
             Bathrooms      = 1,
             GarageCapacity = 1,
             RelatorName    = "Zeinab Dabaj",
             RelatorPhone   = "248-999-2323",
             RelatorEmail   = "*****@*****.**"
         },
             new Property
         {
             Price          = 92000,
             Address        = "3432 MyStreet St",
             City           = "Dearborn Heights",
             Zip            = 48127,
             YearBuilt      = 1925,
             PropertyType   = "condo",
             SquareFeet     = 932,
             Bedrooms       = 2,
             Bathrooms      = 1.5,
             GarageCapacity = 1,
             RelatorName    = "Zeinab Dabaj",
             RelatorPhone   = "248-999-2323",
             RelatorEmail   = "*****@*****.**"
         },
             new Property
         {
             Price          = 128000,
             Address        = "3424 Warren St",
             City           = "Livonia",
             Zip            = 48122,
             YearBuilt      = 1982,
             PropertyType   = "town home",
             SquareFeet     = 1200,
             Bedrooms       = 3,
             Bathrooms      = 2,
             GarageCapacity = 1,
             RelatorName    = "Zeinab Dabaj",
             RelatorPhone   = "248-999-2323",
             RelatorEmail   = "*****@*****.**"
         },
             new Property
         {
             Price          = 4000000,
             Address        = "4555 WestBloom St",
             City           = "Beverly Hills",
             Zip            = 24012,
             YearBuilt      = 2021,
             PropertyType   = "single",
             SquareFeet     = 7921,
             Bedrooms       = 9,
             Bathrooms      = 4,
             GarageCapacity = 2,
             RelatorName    = "Jon Bones",
             RelatorPhone   = "310-212-2323",
             RelatorEmail   = "*****@*****.**"
         },
             new Property
         {
             Price          = 1500000,
             Address        = "3232 Hills St",
             City           = "Beverly Hills",
             Zip            = 24012,
             YearBuilt      = 1999,
             PropertyType   = "condo",
             SquareFeet     = 2500,
             Bedrooms       = 5,
             Bathrooms      = 3,
             GarageCapacity = 2,
             RelatorName    = "Jon Bones",
             RelatorPhone   = "310-212-2323",
             RelatorEmail   = "*****@*****.**"
         },
             new Property
         {
             Price          = 255123,
             Address        = "3381 Glade Creek Blvd",
             City           = "Roanoke",
             Zip            = 24012,
             YearBuilt      = 1966,
             PropertyType   = "single",
             SquareFeet     = 1735,
             Bedrooms       = 4,
             Bathrooms      = 2,
             GarageCapacity = 1.5,
             RelatorName    = "Jon Bones",
             RelatorPhone   = "310-212-2323",
             RelatorEmail   = "*****@*****.**"
         },
             new Property
         {
             Price          = 199500,
             Address        = "9987 Mecca St",
             City           = "Roanoke",
             Zip            = 24012,
             YearBuilt      = 1966,
             PropertyType   = "single",
             SquareFeet     = 1200,
             Bedrooms       = 3,
             Bathrooms      = 1,
             GarageCapacity = 1,
             RelatorName    = "Ahmed Aldhaheri",
             RelatorPhone   = "248-231-2321",
             RelatorEmail   = "*****@*****.**"
         },
             new Property
         {
             Price          = 10000000,
             Address        = "6754 Moe St",
             City           = "Queens",
             Zip            = 24017,
             YearBuilt      = 1932,
             PropertyType   = "single",
             SquareFeet     = 3500,
             Bedrooms       = 6,
             Bathrooms      = 2,
             GarageCapacity = 2,
             RelatorName    = "Ahmed Aldhaheri",
             RelatorPhone   = "248-231-2321",
             RelatorEmail   = "*****@*****.**"
         },
             new Property
         {
             Price          = 3000000,
             Address        = "5734 Brooklyn St",
             City           = "Brooklyn",
             Zip            = 24018,
             YearBuilt      = 1991,
             PropertyType   = "condo",
             SquareFeet     = 2500,
             Bedrooms       = 5,
             Bathrooms      = 3,
             GarageCapacity = 2,
             RelatorName    = "Ahmed Aldhaheri",
             RelatorPhone   = "248-231-2321",
             RelatorEmail   = "*****@*****.**"
         }
             );
         context.SaveChanges();
     }
 }
コード例 #19
0
 public bool SaveChanges()
 {
     return(_context.SaveChanges() >= 0);
 }
コード例 #20
0
 public bool Save()
 {
     // Return value is number of rows affected.
     return(_context.SaveChanges() >= 0);
 }
コード例 #21
0
        private void AddTestData()
        {
            var property1 = new Property()
            {
                PropertyId        = 1,
                Address           = "Dummy Street 56",
                Description       = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries.",
                PictureName       = "picture1",
                Postcode          = "CV6 4PE",
                Price             = 150000,
                PropertyIsDeleted = false
            };

            var property2 = new Property()
            {
                PropertyId        = 2,
                Address           = "Dummy RD 100",
                Description       = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries.",
                PictureName       = "picture2",
                Postcode          = "CV6 4PE",
                Price             = 150000,
                PropertyIsDeleted = false
            };

            var property3 = new Property()
            {
                PropertyId        = 3,
                Address           = "Dummy Street 13",
                Description       = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries.",
                PictureName       = "picture3",
                Postcode          = "CV6 4PE",
                Price             = 150000,
                PropertyIsDeleted = false
            };

            var property4 = new Property()
            {
                PropertyId        = 4,
                Address           = "Dummy Road 145",
                Description       = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries.",
                PictureName       = "picture4",
                Postcode          = "CV6 4PE",
                Price             = 150000,
                PropertyIsDeleted = false
            };

            var property5 = new Property()
            {
                PropertyId        = 5,
                Address           = "Dummy Street 10",
                Description       = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries.",
                PictureName       = "picture3",
                Postcode          = "CV2 4EB",
                Price             = 150000,
                PropertyIsDeleted = false
            };

            var property6 = new Property()
            {
                PropertyId        = 6,
                Address           = "Dummy Road 20",
                Description       = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries.",
                PictureName       = "picture4",
                Postcode          = "CV2 4EB",
                Price             = 150000,
                PropertyIsDeleted = false
            };

            if (!IsRecordExiist(property1.PropertyId))
            {
                _context.Properties.Add(property1);
            }

            if (!IsRecordExiist(property2.PropertyId))
            {
                _context.Properties.Add(property2);
            }

            if (!IsRecordExiist(property3.PropertyId))
            {
                _context.Properties.Add(property3);
            }

            if (!IsRecordExiist(property4.PropertyId))
            {
                _context.Properties.Add(property4);
            }

            if (!IsRecordExiist(property5.PropertyId))
            {
                _context.Properties.Add(property5);
            }

            if (!IsRecordExiist(property6.PropertyId))
            {
                _context.Properties.Add(property6);
            }

            _context.SaveChanges();
        }
コード例 #22
0
 public bool updateOwnerDb(Owner own)
 {
     db.Entry(own).State = EntityState.Modified;
     db.SaveChanges();
     return(true);
 }