protected void RegisterClick(object sender, EventArgs e) { var studentId = this.Students.SelectedValue; if (studentId == null || studentId == "") { this.StudentSelectError.Text = "Student select is required."; this.StudentSelectError.Visible = true; return; } var parentDTO = new RegisterParentDTO() { Email = this.CommonFields.Email, Password = this.CommonFields.Password, FirstName = this.CommonFields.FirstName, LastName = this.CommonFields.LastName, Age = this.CommonFields.Age, ChildId = studentId }; var manager = Context.GetOwinContext().GetUserManager <ApplicationUserManager>(); var ev = new RegisterParentClickEventArgs(parentDTO, manager); this.RegisterParentClick?.Invoke(sender, ev); if (this.Model.IsSuccess) { this.CommonFields.ShowSuccess("Parent registred"); } else { this.CommonFields.ShowError(this.Model.ErrorMessage); } }
public async Task <Parent> RegisterParent(RegisterParentDTO parentModel) { Parent parent = new Parent { UserName = parentModel.UserName, FirstName = parentModel.FirstName, LastName = parentModel.LastName, Email = parentModel.EmailAddress }; return(await db.AuthRepository.RegisterParent(parent, parentModel.Password)); }
public async Task <IHttpActionResult> RegisterParent(RegisterParentDTO parentModel) { if (parentsService.GetAllParents().Select(x => x.UserName).Contains(parentModel.UserName) || parentsService.GetAllParents().Select(x => x.Email).Contains(parentModel.EmailAddress)) { logger.Error("Registering parent - username already exists!"); return(BadRequest("Username already exists!")); } var parent = await service.RegisterParent(parentModel); logger.Info("Registering parent"); return(Ok(parent)); }
public ApplicationUser CreateParent(RegisterParentDTO parentDTO) { var appUser = new ApplicationUser() { UserName = parentDTO.Email, Email = parentDTO.Email, FirstName = parentDTO.FirstName, LastName = parentDTO.LastName, Age = parentDTO.Age, UserType = UserTypes.Parent, ChildId = parentDTO.ChildId, ImageUrl = Constants.DefaultParentImage }; return(appUser); }
public async Task <IdentityResult> RegisterParent(RegisterParentDTO newParent) { ParentModel parent = new ParentModel { UserRole = EUserRole.ROLE_PARENT, FirstName = newParent.FirstName, LastName = newParent.LastName, UserName = newParent.UserName, Email = newParent.Email, PhoneNumber = newParent.MobilePhone }; logger.Info($"New parent created. Parent information - Name: {parent.FirstName}, LastName: {parent.LastName}, Username: {parent.UserName}, DateOfBirth: {parent.Email}"); return(await db.AuthRepository.RegisterParent(parent, newParent.Password)); }
public async Task <IHttpActionResult> PostRegisterParent(RegisterParentDTO parent) { try { var result = await registrationsService.RegisterParent(parent); if (result == null) { return(BadRequest(ModelState)); } return(Created("PostParent", parent)); } catch (InvalidOperationException e) { return(BadRequest(e.Message)); } }
public async Task <IdentityResult> RegisterParent(RegisterParentDTO parentDTO) { Parent found = db.ParentsRepository.GetByUserName(parentDTO.UserName); if (found != null) { return(null); } Parent user = new Parent { UserName = parentDTO.UserName, FirstName = parentDTO.FirstName, LastName = parentDTO.LastName, Email = parentDTO.Email, Jmbg = parentDTO.Jmbg, MobilePhone = parentDTO.MobilePhone }; return(await db.AuthRepository.RegisterParent(user, parentDTO.Password)); }
public IObservable <APIResponse <ParentDTO> > registerParent(RegisterParentDTO parent) { return(Observable.FromAsync(() => PostData <APIResponse <ParentDTO>, RegisterParentDTO>(ApiEndpoints.REGISTER_PARENT, parent))); }
public RegisterParentClickEventArgs(RegisterParentDTO parentDTO, ApplicationUserManager manager) { this.ParentDTO = parentDTO; this.Manager = manager; }
public async Task <IdentityResult> RegisterStudentAndParent(RegisterStudentDTO studentDTO) { Parent parentInTheSystem = db.ParentsRepository.GetByJmbg(studentDTO.ParentJmbg); if (parentInTheSystem != null) { throw new HttpException("The parent with JMBG " + studentDTO.ParentJmbg + " is already in the system " + "with id: " + parentInTheSystem.Id + " Register student" + " with HttpPost at http://localhost:54164/project/account/register-student"); } ApplicationUser foundJmbg = GetByJmbg(studentDTO.Jmbg); if (foundJmbg != null) { throw new HttpException("The user with JMBG " + studentDTO.Jmbg + " is already in the system with id " + foundJmbg.Id); } ApplicationUser foundUserName = await FindUserByUserName(studentDTO.UserName); if (foundUserName != null) { throw new HttpException("The username you entered for the student: " + studentDTO.UserName + " already exists."); } Form form = db.FormsRepository.GetByID(studentDTO.FormId); if (form == null) { throw new HttpException("Form id " + studentDTO.FormId + " was not found."); } ApplicationUser foundParentUserName = await FindUserByUserName(studentDTO.ParentUserName); if (foundParentUserName != null) { throw new HttpException("Username you entered for the parent " + studentDTO.ParentUserName + " already exists."); } RegisterParentDTO parentDTO = new RegisterParentDTO { UserName = studentDTO.ParentUserName, FirstName = studentDTO.ParentFirstName, LastName = studentDTO.ParentLastName, Email = studentDTO.ParentEmail, Password = studentDTO.ParentPassword, ConfirmPassword = studentDTO.ParentConfirmPassword, Jmbg = studentDTO.ParentJmbg, MobilePhone = studentDTO.ParentMobilePhone }; IdentityResult registeredParent = await RegisterParent(parentDTO); if (!registeredParent.Succeeded) { throw new HttpException("Failed to register the parent."); } Parent newParent = db.ParentsRepository.GetByUserName(studentDTO.ParentUserName); if (newParent == null) { throw new HttpException("Something went wrong."); } Student newUser = new Student { UserName = studentDTO.UserName, FirstName = studentDTO.FirstName, LastName = studentDTO.LastName, Email = studentDTO.Email, Jmbg = studentDTO.Jmbg, DayOfBirth = studentDTO.DayOfBirth, IsActive = true, Parent = newParent, Form = form }; IdentityResult regStudent = await db.AuthRepository.RegisterStudent(newUser, studentDTO.Password); if (!regStudent.Succeeded) { throw new HttpException("Failed to register the student."); } emailsService.CreateRegistrationMail(newUser.Id, studentDTO.Password); emailsService.CreateRegistrationMail(newUser.Parent.Id, studentDTO.ParentPassword); emailsService.CreateMailForParentNewStudentAssigned(newUser.Parent.Id); return(regStudent); }