public IActionResult create(CreateNewAppVM vm) { Application a = new Application(); a.ApplicantId = vm.Applicant.ApplicantId; a.CreatedApp = DateTime.Now; a.LastEdited = DateTime.Now; a.Finished = false; a.StatusOfApplication = "Unknown"; Models.Applicant applicant = _db.Applicant.Where(xa => xa.ApplicantId == a.ApplicantId).Include(xq => xq.ApplicationUser).ThenInclude(xe => xe.Country).Include(xw => xw.University).FirstOrDefault(); Info newInfo = new Info(); newInfo.CitizenshipId = applicant.ApplicationUser.CountryId; newInfo.Citizenship = _db.Country.Where(t => t.CountryId == newInfo.CitizenshipId).FirstOrDefault(); a.Infos = newInfo; _db.Info.Add(newInfo); Contact newContact = new Contact(); newContact.Email = applicant.ApplicationUser.Email; newContact.Telephone = applicant.ApplicationUser.PhoneNumber; newContact.Country = null; newContact.CountryId = null; a.Contacts = newContact; _db.Contact.Add(newContact); Language newLang = new Language(); a.Languages = newLang; _db.Language.Add(newLang); HomeInstitution newHI = new HomeInstitution(); newHI.OfficialName = applicant.University.Name; newHI.LevelOfEducation = applicant.StudyCycle; newHI.StudyProgramme = applicant.StudyField; a.HomeInstitutions = newHI; _db.HomeInstitution.Add(newHI); Other newOther = new Other(); a.Others = newOther; _db.Other.Add(newOther); Documents newDocs = new Documents(); a.Documents = newDocs; _db.Documents.Add(newDocs); _db.Application.Add(a); _db.SaveChanges(); return(RedirectToAction("profile", "dashboard", new { id = applicant.ApplicantId })); }
public IActionResult edit(EditAppVM vm) { Application newApp = _db.Application.Where(a => a.ApplicationId == vm.ApplicationId).Include(b => b.Infos).ThenInclude(q => q.Citizenship).Include(c => c.Contacts).Include(d => d.HomeInstitutions).Include(e => e.Others).FirstOrDefault(); Applicant y = _db.Applicant.Where(x => x.ApplicantId == newApp.ApplicantId).Include(b => b.ApplicationUser).ThenInclude(c => c.Country).FirstOrDefault(); Info info = _db.Application.Where(a => a.ApplicationId == newApp.ApplicationId).Include(b => b.Infos).FirstOrDefault().Infos; info.Gender = vm.Application.Infos.Gender; //info.CitizenshipId = vm.Application.Applicant.ApplicationUser.CountryId; //info.CitizenshipId = vm.Application.Infos.CitizenshipId; info.SecondCitizenshipId = vm.Application.Infos.SecondCitizenshipId; info.DateOfBirth = vm.Application.Infos.DateOfBirth; info.PlaceOfBirth = vm.Application.Infos.PlaceOfBirth; info.PassportNumber = vm.Application.Infos.PassportNumber; info.PassportIssueDate = vm.Application.Infos.PassportIssueDate; info.PassportExpiryDate = vm.Application.Infos.PassportExpiryDate; newApp.LastEdited = DateTime.Now; Contact contact = _db.Application.Where(a => a.ApplicationId == newApp.ApplicationId).Include(b => b.Contacts).FirstOrDefault().Contacts; //contact.Email = y.ApplicationUser.Email; //contact.Telephone = y.ApplicationUser.PhoneNumber; contact.StreetName = vm.Application.Contacts.StreetName; contact.PlaceName = vm.Application.Contacts.PlaceName; contact.PostalCode = vm.Application.Contacts.PostalCode; contact.CountryId = vm.Application.Contacts.CountryId; newApp.LastEdited = DateTime.Now; Language lang = _db.Application.Where(a => a.ApplicationId == newApp.ApplicationId).Include(b => b.Languages).FirstOrDefault().Languages; lang.Native = vm.Application.Languages.Native; lang.ForeignFirst = vm.Application.Languages.ForeignFirst; lang.ForeignFirstProficiency = vm.Application.Languages.ForeignFirstProficiency; lang.ForeignSecond = vm.Application.Languages.ForeignSecond; lang.ForeignSecondProficiency = vm.Application.Languages.ForeignSecondProficiency; lang.ForeignThird = vm.Application.Languages.ForeignThird; lang.ForeignThirdProficiency = vm.Application.Languages.ForeignThirdProficiency; lang.ForeignExperienceNumber = vm.Application.Languages.ForeignExperienceNumber; newApp.LastEdited = DateTime.Now; HomeInstitution homeInst = _db.Application.Where(a => a.ApplicationId == newApp.ApplicationId).Include(b => b.HomeInstitutions).FirstOrDefault().HomeInstitutions; //homeInst.OfficialName = _db.Applicant.Where(a => a.ApplicantId == newApp.ApplicantId).FirstOrDefault().University.Name; //homeInst.OfficialName = vm.Application.HomeInstitutions.OfficialName; homeInst.DepartmentName = vm.Application.HomeInstitutions.DepartmentName; //homeInst.LevelOfEducation = vm.Application.HomeInstitutions.LevelOfEducation; homeInst.CurrentTermOrYear = vm.Application.HomeInstitutions.CurrentTermOrYear; //homeInst.StudyProgramme = vm.Application.HomeInstitutions.StudyProgramme; homeInst.CoordinatorFullName = vm.Application.HomeInstitutions.CoordinatorFullName; homeInst.CoordinatorPosition = vm.Application.HomeInstitutions.CoordinatorPosition; homeInst.CoordinatorEmail = vm.Application.HomeInstitutions.CoordinatorEmail; homeInst.CoordinatorPhoneNum = vm.Application.HomeInstitutions.CoordinatorPhoneNum; homeInst.CoordinatorAddress = vm.Application.HomeInstitutions.CoordinatorAddress; Other other = _db.Application.Where(a => a.ApplicationId == newApp.ApplicationId).Include(b => b.Others).FirstOrDefault().Others; other.MedicalInfo = vm.Application.Others.MedicalInfo; other.AdditionalRequests = vm.Application.Others.AdditionalRequests; _db.SaveChanges(); return(RedirectToAction("details", "account", new { id = newApp.ApplicantId })); }