public async Task <IdentityResult> CreateAsync(ApplicationUser user, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); using (var connection = new SqlConnection(_connectionString)) { await connection.OpenAsync(cancellationToken); user.Id = await connection.QuerySingleAsync <int>($@"INSERT INTO [ApplicationUser] ([UserName], [NormalizedUserName], [Email], [NormalizedEmail], [EmailConfirmed], [PasswordHash], [PhoneNumber], [PhoneNumberConfirmed], [TwoFactorEnabled]) VALUES (@{nameof(ApplicationUser.UserName)}, @{nameof(ApplicationUser.NormalizedUserName)}, @{nameof(ApplicationUser.Email)}, @{nameof(ApplicationUser.NormalizedEmail)}, @{nameof(ApplicationUser.EmailConfirmed)}, @{nameof(ApplicationUser.PasswordHash)}, @{nameof(ApplicationUser.PhoneNumber)}, @{nameof(ApplicationUser.PhoneNumberConfirmed)}, @{nameof(ApplicationUser.TwoFactorEnabled)}); SELECT CAST(SCOPE_IDENTITY() as int)", user); } if (user.userType is Lecturer) { lecturerRepository.CreateLecturer(user.userType as Lecturer); } else if (user.userType is Student) { studentRepository.CreateStudent(user.userType as Student); } return(IdentityResult.Success); }
public ActionResult AddLecturer(LecturerAddLecturerViewModel model) { int numberOfRowsAffected = 0; int courseId = 1; // Assume this courseId was acquired from the current HTTP Session. try { string urlEmbeddedAccountActivationToken = lecturerRepository.GenerateRandomUrlEmbeddedAccountActivationToken(); numberOfRowsAffected = lecturerRepository.CreateLecturer(new Lecturer() { staff_id = model.staffId, full_name = model.fullName, contact_number = model.contactNumber, email_address = model.emailAddress, admin = model.admin, course_id = courseId }); //new EmailService().sendNewAccountEmail(model.emailAddress, urlEmbeddedAccountActivationToken, "1184249453"); return(Json(new { rowsAffected = numberOfRowsAffected })); } catch (Exception e) // Generic Exception handler. { return(Json(new { rowsAffected = numberOfRowsAffected, error = e.Message })); } }
public bool CreateLecturer(Lecturer lecturer) { try { var tokenMap = Guid.NewGuid().ToString().Replace("-", "0"); if (lecturer != null && _lecturerRepository.CreateLecturer(lecturer, tokenMap)) { _mailService.SendRegisterMail(lecturer.Email, $"{lecturer.FirstName} {lecturer.LastName}", lecturer.UserRole.ToString(), tokenMap); return(true); } return(false); } catch (Exception e) { return(false); } }
public void CreateLecturer(CreateLecturerDto createLecturerDto) { _lecturerRepository.CreateLecturer(createLecturerDto); }