Example #1
0
 public void Update(Tenant tenant)
 {
     using (var context = new ApartmentContext())
     {
         context.Entry(tenant).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
Example #2
0
 public void Create(Apartment appartment)
 {
     using (var context = new ApartmentContext())
     {
         context.Apartments.Add(appartment);
         context.SaveChanges();
     }
 }
Example #3
0
 public void Create(Tenant tenant)
 {
     using (var context = new ApartmentContext())
     {
         context.Tenants.Add(tenant);
         context.SaveChanges();
     }
 }
 public void Update(Reservation reservation)
 {
     using (var context = new ApartmentContext())
     {
         context.Entry(reservation).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
 public void Create(Reservation reservation)
 {
     using (var context = new ApartmentContext())
     {
         context.Reservations.Add(reservation);
         context.SaveChanges();
     }
 }
Example #6
0
 public void Create(Homeowner homeowner)
 {
     using (var context = new ApartmentContext())
     {
         context.Homeowners.Add(homeowner);
         context.SaveChanges();
     }
 }
Example #7
0
        private UserController SetupDefaultController()
        {
            var options = new DbContextOptionsBuilder <ApartmentContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            using (var context = new ApartmentContext(options))
            {
                context.Users.Add(new User {
                    Id           = 1,
                    Username     = "******",
                    Password     = "******",
                    PasswordSalt = Convert.FromBase64String("SEfcsflTemzwn2t/MP00Mw=="),
                    Role         = Role.Admin
                });
                context.Users.Add(new User {
                    Id           = 2,
                    Username     = "******",
                    Password     = "******",
                    PasswordSalt = Convert.FromBase64String("tYwvfcbNoAFjLOgwhYpGaQ=="),
                    Role         = Role.Realtor
                });
                context.Users.Add(new User {
                    Id           = 3,
                    Username     = "******",
                    Password     = "******",
                    PasswordSalt = Convert.FromBase64String("BAV88E56WMdNcAU5y7ZDfw=="),
                    Role         = Role.Client
                });
                context.SaveChanges();
            }

            var appSettings = new AppSettings {
                Secret = "This is a test Secret string"
            };
            var appSettingOptions = new Mock <IOptions <AppSettings> >();

            appSettingOptions.SetupGet(a => a.Value).Returns(appSettings);
            var mapper     = new Mock <IMapper>();
            var controller = new UserController(
                new ApartmentContext(options),
                appSettingOptions.Object,
                mapper.Object);

            return(controller);
        }
Example #8
0
        static void Main(string[] args)
        {
            //Adding a new person

            using (var apartmentContext = new ApartmentContext())
            {
                Person newPerson = new Person
                {
                    personID      = 1,
                    personName    = "Nihil",
                    personSurname = "Nia"
                };

                apartmentContext.Persons.Add(newPerson);
                apartmentContext.SaveChanges();
            }

            // Adding debt to an exists person

            using (var apartmentContext = new ApartmentContext())
            {
                Person existsPerson = apartmentContext.Persons.Find(1);  //parameter is primary key which is I made it as personID
                existsPerson.personDebts.Add(new Debt {
                    debtID = 1, personID = 123, currentDebt = 1000
                });
                apartmentContext.SaveChanges();
            }


            using (var apartmentContext = new ApartmentContext())
            {
                foreach (var person in apartmentContext.Persons)
                {
                    Console.WriteLine("Person name: " + person.personName);
                }
            }
            Console.ReadLine();
        }
        public IActionResult Create(ContractViewModel contractView)
        {
            if (ModelState.IsValid)
            {
                var contract = new Contract();
                contract.ContractNo    = contractView.ContractNo;
                contract.EngageMonth   = contractView.EngageMonth;
                contract.ContractValue = contractView.ContractValue;
                var customer = new Customer();
                customer.CustomerName   = contractView.CustomerName;
                customer.BirthDay       = contractView.BirthDay;
                customer.Gender         = contractView.Gender;
                customer.IdentityCardNo = contractView.IdentityCardNo;
                customer.DistrictId     = contractView.DistrictId;
                customer.ProvinceId     = contractView.ProvinceId;
                customer.PhoneNo        = contractView.PhoneNo;
                customer.Email          = contractView.Email;
                var room = new Room();
                room.RoomNo     = contractView.RoomNo;
                room.RoomTypeId = contractView.RoomTypeId;
                room.Price      = contractView.Price;
                room.Area       = contractView.Area;

                _context.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.Provinces = new SelectList(_context.Province, "ProvinceId", "ProvinceName", contractView.ProvinceId);
            if (contractView.ProvinceId != null)
            {
                ViewBag.Districts = new SelectList(_context.District.Where(x => x.ProvinceId == contractView.ProvinceId), "DistrictId", "DistrictName", contractView.DistrictId);
            }


            ViewBag.RoomTypes = new SelectList(_context.RoomType, "RoomTypeId", "RoomTypeName", contractView.RoomTypeId);

            return(View(contractView));
        }
        private ApartmentController SetupDefaultController()
        {
            var options = new DbContextOptionsBuilder <ApartmentContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            using (var context = new ApartmentContext(options))
            {
                context.Users.Add(new User
                {
                    Id           = 2,
                    Username     = "******",
                    Password     = "******",
                    PasswordSalt = Convert.FromBase64String("tYwvfcbNoAFjLOgwhYpGaQ=="),
                    Role         = Role.Realtor
                });
                context.Apartments.Add(new Apartment
                {
                    Id            = 1,
                    Name          = "High living",
                    Description   = "Come see the sights from up on high!",
                    Rooms         = 5,
                    Area          = 2000,
                    MonthlyPrice  = 3540,
                    Latitude      = 30,
                    Longitude     = -95,
                    RealtorUserId = 2,
                    IsRented      = false,
                    DateAdded     = new DateTime(2020, 05, 31)
                });
                context.Apartments.Add(new Apartment
                {
                    Id            = 2,
                    Name          = "Next to the water",
                    Description   = "Relax with your own private dock.",
                    Rooms         = 2,
                    Area          = 2500,
                    MonthlyPrice  = 1750,
                    Latitude      = 28,
                    Longitude     = -105,
                    RealtorUserId = 2,
                    IsRented      = true,
                    DateAdded     = new DateTime(2020, 02, 20)
                });
                context.Apartments.Add(new Apartment
                {
                    Id            = 3,
                    Name          = "Low living",
                    Description   = "Stay close to the pulse!",
                    Rooms         = 1,
                    Area          = 500,
                    MonthlyPrice  = 999.99M,
                    Latitude      = 45,
                    Longitude     = -110,
                    RealtorUserId = 2,
                    IsRented      = false,
                    DateAdded     = new DateTime(2020, 03, 01)
                });
                context.SaveChanges();
            }

            var appSettings = new AppSettings {
                Secret = "This is a test Secret string"
            };
            var appSettingOptions = new Mock <IOptions <AppSettings> >();

            appSettingOptions.SetupGet(a => a.Value).Returns(appSettings);
            var controller = new ApartmentController(
                new ApartmentContext(options));

            return(controller);
        }
Example #11
0
 // Save
 public void Save()
 {
     _context.SaveChanges();
 } // end void Save()