public IActionResult SaveLandLordRegistration(AddingLandLordVM model) { if (!ModelState.IsValid) { return(View("LandLordRegistration", LListInput(model))); } var contact = new ContactInfo() { Email = model.Email, Phone = model.PhoneNummber, Address = model.Address }; db.Contact.Add(contact); db.SaveChanges(); var profileInfo = new ProfileInfo() { Username = model.Username, PasswordSalt = PasswordHashAndSalt.GenerateSalt() }; profileInfo.PasswordHash = PasswordHashAndSalt.GenerateHash(profileInfo.PasswordSalt, model.Password); db.ProfileInfo.Add(profileInfo); db.SaveChanges(); var newLandLord = new LandLord() { Fname = model.FName, LName = model.LName, DateOfBirth = model.DateOfBirth, DateAdded = DateTime.Today, ContactInfoId = contact.Id, CityId = model.CityId, StatusId = 1, GenderId = model.GenderId, ProfileInfoId = profileInfo.Id }; db.LandLord.Add(newLandLord); db.SaveChanges(); return(RedirectToAction("Index")); }
//public IActionResult TeacherRegistration() //{ // var newRegistration = new TeacherRegistrationVM(); // newRegistration.typeOfStudents = new List<TypeOfStudentsFilter>(); // var studentTypes = db.StudentType.ToList(); // foreach (var type in studentTypes) // { // var newFilter = new TypeOfStudentsFilter() // { // StudentTypeId = type.Id, // Type = type.Type, // Checked = false // }; // newRegistration.typeOfStudents.Add(newFilter); // } // return View(model:TeacherInput(newRegistration)); //} //public IActionResult SaveTeacherRegistration(TeacherRegistrationVM model) //{ // if (!ModelState.IsValid) // { // return View("TeacherRegistration", TeacherInput(model)); // } // var contact = new ContactInfo() // { // Email = model.Email, // Phone = model.PhoneNummber, // Address = model.Address // }; // db.Contact.Add(contact); // db.SaveChanges(); // var profileInfo = new ProfileInfo() // { // Username = model.Username, // PasswordSalt = PasswordHashAndSalt.GenerateSalt() // }; // profileInfo.PasswordHash = PasswordHashAndSalt.GenerateHash(profileInfo.PasswordSalt, model.Password); // db.ProfileInfo.Add(profileInfo); // db.SaveChanges(); // var newTutor = new TutorRegistrationForm() // { // FName=model.FName, // LName = model.LName, // ProfileInfoId=profileInfo.Id, // DateOfBirth = model.DateOfBirth, // CollageName = model.CollageName, // Price = model.Price, // TitleId = model.TitleId, // SubjectId = model.SubjectId, // ContactInfoId = contact.Id, // CityId=model.CityId, // GenderId=model.GenderId, // IsRead=false // }; // if (model.ProfilePicture != null) // { // var fileExst = Path.GetExtension(model.ProfilePicture.FileName); // var newFileName = Convert.ToString(Guid.NewGuid())+fileExst; // var fileName = Path.Combine(hostingEnvironment.WebRootPath, "Profilepictures")+$@"\{newFileName}"; // var databaseName = "/Profilepictures/" + newFileName; // model.ProfilePicture.CopyTo(new FileStream(fileName, FileMode.Create)); // newTutor.ProfilePicture = databaseName; // } // db.TutorRegistrationForm.Add(newTutor); // db.SaveChanges(); // foreach (var item in model.typeOfStudents) // { // if (item.Checked) // { // var PerferedType = new ListOfStudents() // { // TutorRegistrationFormId = newTutor.Id, // StudentTypeId = item.StudentTypeId // }; // db.ListOfStudents.Add(PerferedType); // db.SaveChanges(); // } // } // foreach (var item in model.Proof) // { // var fileExst = Path.GetExtension(item.FileName); // var newFileName = Convert.ToString(Guid.NewGuid()) + fileExst; // var fileName = Path.Combine(hostingEnvironment.WebRootPath, "ProofPictures") + $@"\{newFileName}"; // item.CopyTo(new FileStream(fileName, FileMode.Create)); // var databaseName = "/ProofPictures/" + newFileName; // var proofPicture = new Proof() // { // TutorRegistrationFormId=newTutor.Id, // PictureName= databaseName // }; // db.Proof.Add(proofPicture); // } // db.SaveChanges(); // return RedirectToAction("Index"); //} private AddingLandLordVM LListInput(AddingLandLordVM viewModel) { if (viewModel.Citys == null) { viewModel.Citys = db.City.Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.Name }).ToList(); } if (viewModel.Gender == null) { viewModel.Gender = db.Gender.Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.UserGender }).ToList(); } return(viewModel); }
public IActionResult LandLordRegistration() { var landLordReg = new AddingLandLordVM(); return(View(model: LListInput(landLordReg))); }