/// <summary> /// Registers a new employer and also its initiator employer person. /// </summary> /// <param name="employerPerson"></param> public void RegisterEmployer(EmployerPerson employerPerson) { using (var db = new JobyJobsDB2()) { //adds the user (under same transaction). Guid employerUID = employerPerson.Employer.EmployerUID != Guid.Empty ? employerPerson.Employer.EmployerUID : Guid.NewGuid(); string identityUserId = employerPerson.Identity_UserID ?? Guid.NewGuid().ToString(); var dbUser = new user() { Id = identityUserId, UserName = employerPerson.Email, //user as email. PasswordHash = employerPerson.PasswordHash, Email = employerPerson.Email, PhoneNumber = employerPerson.PhoneNumber }; _sp.GetService <IUsersBL>().AddUser(dbUser, Enums.UserRoles.Employer, db); //adds the employer (under same transaction). var employer = employerPerson.Employer; employer.EmployerUID = employerUID; employer.JoinDate = DateTime.Now; employer.Active = true; db.employers.Add(employer.ToDB()); //adds the employer person. employerPerson.Identity_UserID = identityUserId; employerPerson.RegisterDate = DateTime.Now; employerPerson.Active = true; var dbEmployerPerson = employerPerson.ToDB(); db.employer_persons.Add(dbEmployerPerson); //saves all work. db.SaveChanges(); } }
/// <summary> /// Registers a new employer person and assigns them to an existing employer. /// Note: Recipient side. /// </summary> /// <param name="employerPerson"></param> public void RegisterEmployerPerson(Guid inviteUID, EmployerPerson employerPerson) { using (var db = new JobyJobsDB2()) { //pulls out the employerId from the invitation object. employer_persons_invites inviteObj = db.employer_persons_invites.Single(item => item.invite_uid == inviteUID.ToString()); int employerId = inviteObj.employer_persons.employer_id; string identityUserId = employerPerson.Identity_UserID ?? Guid.NewGuid().ToString(); var dbUser = new user() { Id = identityUserId, UserName = employerPerson.Email, //user as email. PasswordHash = employerPerson.PasswordHash, Email = employerPerson.Email, PhoneNumber = employerPerson.PhoneNumber }; //update its status to accepted. inviteObj.status_id = (int)Enums.EmployerPersonInviteStatuses.Accepted; db.Entry(inviteObj).State = EntityState.Modified; //adds the user (under same transaction). _sp.GetService <IUsersBL>().AddUser(dbUser, Enums.UserRoles.Employer, db); //sets the employerId of the employer person. employerPerson.EmployeryId = employerId; //adds the employer person. var dataTimeNow = DateTime.Now; employerPerson.Identity_UserID = identityUserId; employerPerson.RegisterDate = dataTimeNow; employerPerson.Active = true; var dbEmployerPerson = employerPerson.ToDB(); db.employer_persons.Add(dbEmployerPerson); //saves all work. db.SaveChanges(); } }