public void AddMentor(MentorModel model) { //validate model model.Validate(); //Check if mentor record already exists var mentor = _repo.GetMentor(model.UserId); if (mentor != null) { throw new Exception("This record already exists!!!"); } _repo.AddMentor(model); }
public IActionResult Create([FromBody] MentorUserDetails mentor) { if (mentor == null) { return(BadRequest(ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_mentorRepository.AddMentor(mentor)) { ModelState.AddModelError("", "Something went wrong."); return(StatusCode(500, ModelState)); } return(CreatedAtRoute("Mentor", new { id = mentor.Id }, mentor)); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); if (ModelState.IsValid) { var user = new ApplicationUser { FirstName = Input.FirstName, LastName = Input.LastName, UserName = Input.Email, Email = Input.Email, UserRole = Input.UserRole }; var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); var userId = _userManager.Users.SingleOrDefault(i => i.Email == user.Email).Id; var role = Input.UserRole; switch (role) { case "Client": if (userId != null) { var client = new ClientUserDetails { ApplicationUserId = userId }; _clientRepository.AddClient(client); } break; case "Mentor": if (userId != null) { var mentor = new MentorUserDetails { ApplicationUserId = userId }; _mentorRepository.AddMentor(mentor); } break; case "HR": if (userId != null) { var HR = new HrUserDetails { ApplicationUserId = userId }; _hrRepository.AddHr(HR); } break; case "Admin": if (userId != null) { var admin = new AdministratorDetails { ApplicationUserId = userId }; _administratorDetailsRepository.AddAdministrator(admin); } break; } var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { area = "Identity", userId = user.Id, code = code }, protocol: Request.Scheme); await _emailSender.SendEmailAsync(Input.Email, "Confirm your email", $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); //Προσθέτω μετά το Register το User στο Role εγγραφή στον ενδιάμεσο πίνακα Σπυροσσ await _userManager.AddToRoleAsync(user, Input.UserRole); if (_userManager.Options.SignIn.RequireConfirmedAccount) { return(RedirectToPage("RegisterConfirmation", new { email = Input.Email })); } else { await _signInManager.SignInAsync(user, isPersistent : false); return(LocalRedirect(returnUrl)); } } foreach (var error in result.Errors) { ModelState.AddModelError("Error", error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }
public IActionResult Post([FromBody] Mentor item) { _repository.AddMentor(item); return(Ok("Record Added")); }
public MentorRegistrationResponse AddMentor(MentorRegistrationRequest mentorRegistration) { var responseData = _mentorRepository.AddMentor(mentorRegistration); return(responseData); }