public static MentorApplication GetMentorApplicationByPersonId(ref DAO.ApplicationContext context, int id) { MentorApplication application = (from r in context.MentorApplications where r.PersonId == id select r).FirstOrDefault(); return(application); }
/// <summary> /// Promote a mentor application /// </summary> /// <param name="id"></param> /// <param name="registrationStatusId"></param> /// <returns></returns> public JsonResult Promote(int id, int statusId) { string message = "failed"; // Find the mentor application MentorApplication app = RegistrationHelper.GetMentorApplicationById(ref _db, id); if (app != null) { // Change the application status app.StatusId = statusId; // Save the application _db.SaveChanges(); // Success message = "success"; } return(Json(message)); }
public ActionResult Create(RegistrationViewModel viewModel) { int mentorAppId = 0; if (viewModel.AgreeToTerms == 1) { // ================================================================= // Save the mentor application details // ================================================================= MentorApplication application = new MentorApplication(viewModel); application.RegistrationDate = DateTime.Now; this._db.MentorApplications.Add(application); this._db.SaveChanges(); // We need to save the application id for use later mentorAppId = application.id; // ================================================================= // Create the Person Record // ================================================================= Person newPerson = new Person(viewModel); this._db.People.Add(newPerson); this._db.SaveChanges(); // ================================================================= // Addresses (Home address is the only one right now that we care about) // ================================================================= Address newAddress = new Address(viewModel); this._db.Addresses.Add(newAddress); this._db.SaveChanges(); // Add the address cross reference PersonAddress addrToPerson = new PersonAddress(newPerson.id, newAddress.id, DomainHelper.GetIdByKeyValue(ref this._db, "AddressType", "Home")); this._db.PersonToAddress.Add(addrToPerson); this._db.SaveChanges(); // ================================================================= // Phone Numbers // ================================================================= Phone homePhone = new Phone(viewModel.HomePhone.CountryCode, viewModel.HomePhone.AreaCode, viewModel.HomePhone.PrefixCode, viewModel.HomePhone.SuffixCode); // Add the phone number to the database this._db.PhoneNumbers.Add(homePhone); this._db.SaveChanges(); // Add the phone number cross reference PersonPhone personPhoneHome = new PersonPhone(homePhone.id, newPerson.id, DomainHelper.GetIdByKeyValue(ref this._db, "PhoneType", "Home")); this._db.PersonToPhone.Add(personPhoneHome); this._db.SaveChanges(); // ================================================================= // Phone Numbers // ================================================================= Phone workPhone = new Phone(viewModel.WorkPhone.CountryCode, viewModel.WorkPhone.AreaCode, viewModel.WorkPhone.PrefixCode, viewModel.WorkPhone.SuffixCode); // Add the phone number to the database this._db.PhoneNumbers.Add(workPhone); this._db.SaveChanges(); // Add the phone number cross reference PersonPhone personPhoneWork = new PersonPhone(workPhone.id, newPerson.id, DomainHelper.GetIdByKeyValue(ref this._db, "PhoneType", "Work")); this._db.PersonToPhone.Add(personPhoneWork); this._db.SaveChanges(); } return(RedirectToAction("Status", new { id = mentorAppId })); }
public static RegistrationViewModel FindRegistration(ref DAO.ApplicationContext context, string username) { int personId = AccountHelper.GetUserIdByUsername(ref context, username); if (personId > 0) { RegistrationViewModel viewModel = new RegistrationViewModel(); int homeAddrType = DomainHelper.GetIdByKeyValue(ref context, "AddressType", "Home"); int workAddrType = DomainHelper.GetIdByKeyValue(ref context, "AddressType", "Work"); MentorApplication data = (MentorApplication)(from r in context.MentorApplications where r.PersonId == personId select r).FirstOrDefault(); UserProfile profile = (UserProfile)(from r in context.UserProfiles where r.PersonId == personId select r).FirstOrDefault(); Person mentor = (Person)(from r in context.People where r.id == personId select r).FirstOrDefault(); Address homeAddr = (Address)(from r in context.Addresses join c in context.PersonToAddress on r.id equals c.AddressId where c.PersonId == personId && c.AddressType == homeAddrType select r).FirstOrDefault(); Address workAddr = (Address)(from r in context.Addresses join c in context.PersonToAddress on r.id equals c.AddressId where c.PersonId == personId && c.AddressType == workAddrType select r).FirstOrDefault(); viewModel.AgreeToTerms = data.AgreeToTerms; viewModel.Availability = data.Availability; viewModel.DateOfBirth = mentor.DOB; viewModel.FelonyArrested = mentor.FelonyArrested; viewModel.FelonyConvicted = mentor.FelonyConvicted; viewModel.FelonyDescription = mentor.FelonyDescription; viewModel.FirstName = mentor.FirstName; viewModel.GenderId = mentor.GenderId; viewModel.HasRelationIncarcerated = data.HasRelationIncarcerated; viewModel.HomeAddress = homeAddr; viewModel.LastName = mentor.LastName; viewModel.LeadershipSkills = data.LeadershipSkills; viewModel.MaidenName = mentor.MaidenName; viewModel.MiddleInitial = mentor.MiddleInitial; viewModel.MinistryExperience = data.MinistryExperience; viewModel.MinistryId = data.MinistryId; viewModel.MisdemeanorArrested = mentor.MisdemeanorArrested; viewModel.MisdemeanorConvicted = mentor.MisdemeanorConvicted; viewModel.MisdemeanorDescription = mentor.MisdemeanorDescription; viewModel.PersonId = mentor.id; viewModel.PrefixId = mentor.PrefixId; viewModel.RaceId = mentor.RaceId; viewModel.RelationIncarceratedName = data.RelationIncarceratedName; viewModel.RelationIncarceratedNumber = data.RelationIncarceratedNumber; viewModel.RelationIncarceratedType = data.RelationIncarceratedType; viewModel.RelativesWorkingForDoC = data.RelativesWorkingForDoC; viewModel.RelativeWorkingForDoCName = data.RelativeWorkingForDoCName; viewModel.RelativeWorkingForDoCRelationType = data.RelativeWorkingForDoCRelationType; viewModel.RelativeWorkingForDoCWorkLocation = data.RelativeWorkingForDoCWorkLocation; viewModel.SocialSecurityNumber = mentor.SSN; viewModel.SpecialHobbies = data.SpecialHobbies; viewModel.SpecialRequests = data.SpecialRequests; viewModel.StateDl = mentor.StateDl; viewModel.StateWhereDlIssued = mentor.StateWhereDlWasIssued; viewModel.SuffixId = mentor.SuffixId; if (data.WhenWorkedEnded != null) { viewModel.WhenWorkedEnded = data.WhenWorkedEnded.Value; } if (data.WhenWorkedStarted != null) { viewModel.WhenWorkedStarted = data.WhenWorkedStarted.Value; } viewModel.WhereDidYouWork = data.WhereDidYouWork; viewModel.WorkAddress = workAddr; viewModel.WorkedForDoC = data.WorkedForDoC; viewModel.Username = profile.Username; return(viewModel); } else { return(null); } }