public async Task <ActionResult> AddApartment(ApartmentAdd model) { if (ModelState.IsValid) { ApplicationContext db = new ApplicationContext(); var current_user = db.Users.Where(x => x.Email == HttpContext.User.Identity.Name).SingleOrDefault(); var current_address = db.Addresses.Where(x => x.Country == model.Country && x.Area == model.Area && x.City == model.City && x.District == model.District && x.Street == model.Street && x.House == model.House && x.Apartment == model.Apartment).SingleOrDefault(); int addressID = 0; if (current_address == null) { Address address = new Address { Country = model.Country, Area = model.Area, City = model.City, District = model.District, Street = model.Street, House = model.House, Apartment = model.Apartment }; db.Addresses.Add(address); db.SaveChanges(); addressID = address.Id; } else { addressID = current_address.Id; } Apartment apartment = new Apartment { Florr = model.Florr, Num_Floors = model.Num_Floors, Num_Rooms = model.Num_Rooms, Total_Area = model.Total_Area, LivingArea = model.LivingArea, KitchenArea = model.KitchenArea, Price = model.Price, rf_UsersId = current_user.Id, rf_TypeHomeId = model.rf_TypeHomeId, rf_AdressId = addressID }; db.Apartments.Add(apartment); db.SaveChanges(); //IdentityResult result = await UserManager.CreateAsync(user, model.Password); return(RedirectToAction("Index", "Home")); } return(View(model)); }
protected override void Seed(PropertyManager.Models.ApplicationDbContext context) { // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. E.g. // // context.People.AddOrUpdate( // p => p.FullName, // new Person { FullName = "Andrew Peters" }, // new Person { FullName = "Brice Lambson" }, // new Person { FullName = "Rowan Miller" } // ); // if (!(context.Users.Any(u => u.UserName == "*****@*****.**"))) { var userStore = new UserStore <ApplicationUser>(context); var userManager = new UserManager <ApplicationUser>(userStore); var userToInsert = new ApplicationUser { UserName = "******", Email = "*****@*****.**", GivenName = "Amanda", Surname = "Cruz", Role = "Manager" }; userManager.Create(userToInsert, "PropertyApp123"); userManager.AddClaim(userToInsert.Id, new Claim(ClaimTypes.Role, "Manager")); } if (!(context.Users.Any(u => u.UserName == "*****@*****.**"))) { var userStore = new UserStore <ApplicationUser>(context); var userManager = new UserManager <ApplicationUser>(userStore); var userToInsert = new ApplicationUser { UserName = "******", Email = "*****@*****.**", GivenName = "Administrator", Surname = "Adm", Role = "Administrator" }; userManager.Create(userToInsert, "PropertyApp123"); userManager.AddClaim(userToInsert.Id, new Claim(ClaimTypes.Role, "Administrator")); } if (!(context.Users.Any(u => u.UserName == "*****@*****.**"))) { var userStore = new UserStore <ApplicationUser>(context); var userManager = new UserManager <ApplicationUser>(userStore); var userToInsert = new ApplicationUser { UserName = "******", Email = "*****@*****.**", GivenName = "Amanda", Surname = "Marques", Role = "Tenant" }; userManager.Create(userToInsert, "Asdf4321!"); userManager.AddClaim(userToInsert.Id, new Claim(ClaimTypes.Role, "Tenant")); } //UNIT if (m.UnitGetAll().Count() == 0) { var unit = new UnitAdd(); unit.Bedrooms = 2; unit.Bathrooms = 1; unit.SquareFeet = 100.5; unit.MaxOccupants = 3; unit.Balcony = true; unit.Dishwasher = true; unit.Laundry = false; m.UnitAdd(unit); unit.Bedrooms = 1; unit.Bathrooms = 1; unit.SquareFeet = 87.5; unit.MaxOccupants = 2; unit.Balcony = true; unit.Dishwasher = false; unit.Laundry = false; m.UnitAdd(unit); unit.Bedrooms = 3; unit.Bathrooms = 2; unit.SquareFeet = 130.0; unit.MaxOccupants = 5; unit.Balcony = true; unit.Dishwasher = true; unit.Laundry = true; m.UnitAdd(unit); } if (m.ApartmentGetAll().Count() == 0) { var apt = new ApartmentAdd(); apt.ApartmentNumber = 520; apt.FloorNumber = 5; apt.Status = "Occupied"; apt.UnitId = 1; m.ApartmentAdd(apt); apt.ApartmentNumber = 603; apt.FloorNumber = 6; apt.Status = "Occupied"; apt.UnitId = 2; m.ApartmentAdd(apt); apt.ApartmentNumber = 1705; apt.FloorNumber = 17; apt.Status = "Occupied"; apt.UnitId = 3; m.ApartmentAdd(apt); } if (m.TenantGetAll().Count() == 0) { var tenant = new TenantAdd(); tenant.FirstName = "Amanda"; tenant.LastName = "Marques"; tenant.MobilePhone = "647-535-7732"; tenant.HomePhone = ""; tenant.Email = "*****@*****.**"; tenant.BirthDate = new DateTime(1988, 12, 23); m.TenantAdd(tenant); tenant.FirstName = "Jonathan"; tenant.LastName = "Desmond"; tenant.MobilePhone = "536-85-96415"; tenant.HomePhone = "365-459-8752"; tenant.Email = "*****@*****.**"; tenant.BirthDate = new DateTime(1990, 10, 18); m.TenantAdd(tenant); tenant.FirstName = "Carlos"; tenant.LastName = "Wellinton"; tenant.MobilePhone = "963-125-4789"; tenant.HomePhone = "964-585-3658"; tenant.Email = "*****@*****.**"; tenant.BirthDate = new DateTime(1994, 09, 21); m.TenantAdd(tenant); } if (m.LeaseGetAllWithInformation().Count() == 0) { var lease = new LeaseAdd(); lease.StartDate = new DateTime(2016, 01, 01); lease.EndDate = new DateTime(2018, 01, 01); lease.SecurityDeposit = 500.00; lease.MonthlyRent = 1050.60; lease.ApartmentNumber = 520; lease.TenantId = 1; m.LeaseAdd(lease); lease.StartDate = new DateTime(2017, 08, 20); lease.EndDate = new DateTime(2018, 08, 19); lease.SecurityDeposit = 430.00; lease.MonthlyRent = 1200.50; lease.ApartmentNumber = 603; lease.TenantId = 2; m.LeaseAdd(lease); lease.StartDate = new DateTime(2016, 04, 01); lease.EndDate = new DateTime(2017, 04, 01); lease.SecurityDeposit = 525.00; lease.MonthlyRent = 1400.80; lease.ApartmentNumber = 1705; lease.TenantId = 3; m.LeaseAdd(lease); } if (m.EmployeeGetAll().Count() == 0) { var employee = new EmployeeAdd(); employee.LastName = "Marques"; employee.FirstName = "Amanda"; employee.Title = "Supervisor"; employee.BirthDate = new DateTime(1988, 12, 23); employee.HireDate = new DateTime(2017, 02, 06); employee.Address = "Wellesley St"; employee.City = "Toronto"; employee.State = "ON"; employee.Country = "Canada"; employee.PostalCode = "M4X-1G5"; employee.Email = "*****@*****.**"; employee.Phone = "647-589-5357"; m.EmployeeAdd(employee); employee.LastName = "Desmond"; employee.FirstName = "Jonathan"; employee.Title = "Manager"; employee.BirthDate = new DateTime(1990, 11, 16); employee.HireDate = new DateTime(2017, 01, 05); employee.Address = "Pond Rd"; employee.City = "Toronto"; employee.State = "ON"; employee.Country = "Canada"; employee.PostalCode = "M6H 1Y7"; employee.Email = "*****@*****.**"; employee.Phone = "647-896-5236"; m.EmployeeAdd(employee); employee.LastName = "Capello"; employee.FirstName = "Silvia"; employee.Title = "Clerk"; employee.BirthDate = new DateTime(1958, 01, 09); employee.HireDate = new DateTime(2016, 04, 28); employee.Address = "Aluisio St"; employee.City = "Toronto"; employee.State = "ON"; employee.Country = "Canada"; employee.PostalCode = "J7G 1S3"; employee.Email = "*****@*****.**"; employee.Phone = "647-652-3105"; m.EmployeeAdd(employee); } if (m.AnnouncementGetAll().Count() == 0) { var announce = new AnnouncementAdd(); announce.Title = "Laundry closed"; announce.StartDate = new DateTime(2017, 05, 05); announce.ExpireDate = new DateTime(2017, 05, 06); announce.Description = "The laundry room will be closed for maintenance"; m.AnnouncementAdd(announce); announce.Title = "Cleaning of corridor"; announce.StartDate = new DateTime(2017, 04, 20); announce.ExpireDate = new DateTime(2017, 04, 22); announce.Description = "The carpet will be cleaned on the upcoming weekend"; m.AnnouncementAdd(announce); announce.Title = "New Recycle Bins"; announce.StartDate = new DateTime(2017, 03, 10); announce.ExpireDate = new DateTime(2017, 03, 11); announce.Description = "The apartments will be receiving new recycle bins starting next week"; m.AnnouncementAdd(announce); } if (m.FacilityGetAll().Count() == 0) { var facility = new FacilityAdd(); facility.FacilityName = "Pool"; facility.Description = "Open Pool"; facility.Location = "40th floor"; facility.Status = "Open"; facility.OpenTime = new DateTime(2017, 01, 01, 08, 0, 0); facility.CloseTime = new DateTime(2017, 02, 01, 18, 0, 0); m.FacilityAdd(facility); facility.FacilityName = "Movie Room"; facility.Description = "Movie Theater"; facility.Location = "Lobby"; facility.Status = "Open"; facility.OpenTime = new DateTime(2017, 02, 01, 10, 0, 0); facility.CloseTime = new DateTime(2017, 02, 01, 20, 30, 0); m.FacilityAdd(facility); } if (m.InventoryGetAll().Count() == 0) { var inventory = new InventoryAdd(); inventory.ProductName = "Cleaning"; inventory.Supplier = "Lisol"; inventory.Quantity = 20; m.InventoryAdd(inventory); inventory.ProductName = "Garbage Bag"; inventory.Supplier = "My Garbages"; inventory.Quantity = 100; m.InventoryAdd(inventory); inventory.ProductName = "Window cleaning"; inventory.Supplier = "Windex"; inventory.Quantity = 87; m.InventoryAdd(inventory); } if (m.ServiceGetAll().Count() == 0) { var service = new ServiceAdd(); service.ServiceName = "Gardening"; service.CompanyName = "Gardening Express"; service.PhoneNumber = "416-547-8963"; service.Email = "*****@*****.**"; service.Address = "346 Allen Rd"; m.ServiceAdd(service); service.ServiceName = "Pest Control"; service.CompanyName = "Pest Rock"; service.PhoneNumber = "647-514-8965"; service.Email = "*****@*****.**"; service.Address = "1549 Dufferin St"; m.ServiceAdd(service); service.ServiceName = "Cleaning"; service.CompanyName = "Nice Cleaning"; service.PhoneNumber = "907-534-8698"; service.Email = "*****@*****.**"; service.Address = "15 Bloor St"; m.ServiceAdd(service); } if (m.WorkOrderGetAll().Count() == 0) { var workOrder = new WorkOrderAdd(); workOrder.Description = "Fixing light bulb"; workOrder.Notes = "In the living room"; workOrder.RequestDate = new DateTime(2017, 02, 26); workOrder.TenantId = 1; m.WorkOrderAdd(workOrder); workOrder.Description = "Kill bugs"; workOrder.Notes = "Many bugs in the house"; workOrder.RequestDate = new DateTime(2017, 04, 05); workOrder.TenantId = 2; m.WorkOrderAdd(workOrder); workOrder.Description = "Leaking in the kitchen"; workOrder.Notes = "My sink is full of water"; workOrder.RequestDate = new DateTime(2017, 05, 22); workOrder.TenantId = 3; m.WorkOrderAdd(workOrder); } if (m.ServiceRequestGetAll().Count() == 0) { var request = new ServiceRequestAdd(); request.Description = "Monthly Cleaning"; request.RequestDate = new DateTime(2017, 03, 01); request.ServiceId = 3; m.ServiceRequestAdd(request); request.Description = "Doing gardening"; request.RequestDate = new DateTime(2016, 05, 05); request.ServiceId = 1; m.ServiceRequestAdd(request); request.Description = "Building Pest Control"; request.RequestDate = new DateTime(2017, 04, 23); request.ServiceId = 2; m.ServiceRequestAdd(request); } if (m.FacilityBookingGetAllWithFacility().Count() == 0) { var booking = new FacilityBookingAdd(); booking.BookedDate = new DateTime(2017, 05, 22); booking.StartTime = new DateTime(2017, 05, 22, 10, 30, 0); booking.EndTime = new DateTime(2017, 05, 22, 17, 0, 0); booking.TenantId = 1; booking.FacilityId = 1; booking.Notes = "No Notes"; m.FacilityBookingAdd(booking); booking.BookedDate = new DateTime(2017, 10, 01); booking.StartTime = new DateTime(2017, 10, 01, 13, 0, 0); booking.EndTime = new DateTime(2017, 10, 01, 14, 45, 0); booking.TenantId = 2; booking.FacilityId = 2; booking.Notes = ""; m.FacilityBookingAdd(booking); booking.BookedDate = new DateTime(2017, 10, 01); booking.StartTime = new DateTime(2017, 10, 01, 15, 0, 0); booking.EndTime = new DateTime(2017, 10, 01, 18, 0, 0); booking.TenantId = 3; booking.FacilityId = 2; booking.Notes = ""; m.FacilityBookingAdd(booking); booking.BookedDate = new DateTime(2017, 04, 05); booking.StartTime = new DateTime(2017, 04, 05, 10, 0, 0); booking.EndTime = new DateTime(2017, 04, 05, 13, 10, 0); booking.TenantId = 1; booking.FacilityId = 2; booking.Notes = ""; m.FacilityBookingAdd(booking); } if (m.OccupantGetAll().Count() == 0) { var occupant = new OccupantAdd(); occupant.FirstName = "Silvia"; occupant.LastName = "Capello"; occupant.MobilePhone = "647-415-8957"; occupant.WorkPhone = "416-548-9569"; occupant.Email = "*****@*****.**"; occupant.BirthDate = new DateTime(1958, 01, 09); occupant.ApartmentNumber = 520; occupant.TenantId = 1; m.OccupantAdd(occupant); occupant.FirstName = "Renan"; occupant.LastName = "Marques"; occupant.MobilePhone = "647-485-9874"; occupant.WorkPhone = "416-123-5647"; occupant.Email = "*****@*****.**"; occupant.BirthDate = new DateTime(1990, 07, 02); occupant.ApartmentNumber = 520; occupant.TenantId = 1; m.OccupantAdd(occupant); occupant.FirstName = "Jennifer"; occupant.LastName = "Aniston"; occupant.MobilePhone = "905-452-7415"; occupant.WorkPhone = "416-987-4256"; occupant.Email = "*****@*****.**"; occupant.BirthDate = new DateTime(1992, 03, 20); occupant.ApartmentNumber = 603; occupant.TenantId = 2; m.OccupantAdd(occupant); occupant.FirstName = "Mayra"; occupant.LastName = "Borne"; occupant.MobilePhone = "905-471-3589"; occupant.WorkPhone = "416-416-8526"; occupant.Email = "*****@*****.**"; occupant.BirthDate = new DateTime(2000, 05, 21); occupant.ApartmentNumber = 603; occupant.TenantId = 2; m.OccupantAdd(occupant); occupant.FirstName = "Tania"; occupant.LastName = "Wellinton"; occupant.MobilePhone = "905-965-7854"; occupant.WorkPhone = "364-654-5984"; occupant.Email = "*****@*****.**"; occupant.BirthDate = new DateTime(1960, 03, 27); occupant.ApartmentNumber = 1705; occupant.TenantId = 3; m.OccupantAdd(occupant); } }
public ActionResult AddApartment() { var model = new ApartmentAdd(); return(View(model)); }