public ActionResult CreateParticipant(ParticipantRegisterViewModel participantRegisterModel) { IRegisterHandler registerHandler = new RegisterHandler(new bachelordbContext()); Participant currentp = new Participant(); currentp.Email = participantRegisterModel.Email; currentp.Password = participantRegisterModel.Password; currentp.Age = participantRegisterModel.Age; currentp.English = participantRegisterModel.Language; if (participantRegisterModel.GenderType == Gender.Male) { currentp.Gender = true; } else { currentp.Gender = false; } bool success = registerHandler.RegisterParticipantDB(currentp); if (!success) { //User not saved in db this.ModelState.AddModelError("Email", "Email already exists"); return(View("Participant")); } return(RedirectToAction("LoginParticipant", "Welcome", currentp)); }
public static BachelorBackEnd.participants ParticipantobjFromViewToDto(ParticipantRegisterViewModel registerobj) { BachelorBackEnd.participants currentParticipants = new participants(); if (registerobj != null) { currentParticipants.firstname = registerobj.Firstname; currentParticipants.email = registerobj.Email; currentParticipants.lastname = registerobj.Lastname; currentParticipants.password = registerobj.Password; currentParticipants.pause = 0; } return(currentParticipants); }
public ActionResult ParticipentRegister([Bind("Email,Firstname,Lastname,Password")] ParticipantRegisterViewModel participantRegisterobj) { BachelorBackEnd.participants currentParticipants = RegisterConverter.ParticipantobjFromViewToDto(participantRegisterobj); DataAcess = new DalParticipant(); DataAcess.SaveRegisterDto(currentParticipants); try { return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public IActionResult Store(ParticipantRegisterViewModel model) { try { if (ModelState.IsValid) { Participant participant = _participantRepository.FindUniqueByEmail(model.Email); if (participant != null) { ModelState.AddModelError("Email", "E-mail já cadastrado"); return(View("Index", model)); } participant = new Participant { Name = model.Name, Email = model.Email, Birthdate = model.Birthdate, Gender = model.Gender, Password = HashExtension.Create(model.Password, Environment.GetEnvironmentVariable("AUTH_SALT")), CreatedAt = DateTime.Now }; _participantRepository.Add(participant); _participantRepository.SaveChanges(); TempData["Success"] = "Registro efetuado com sucesso!"; return(RedirectToAction("Index", "Login")); } } catch (Exception exception) { TempData["Error"] = "Internal server error"; _logger.LogError("Login error: " + exception); } return(View("Index", model)); }