public ActionResult CreateClient(GebruikerViewModel.CreateClientViewModel model) { if (UserStillLoggedIn() || _gebruikerRepository.FindById((int)Session["gebruiker"]) is Client) { return ReturnToLogin(); } if (ModelState.IsValid) { try { if (model.GeselecteerdOpvangtehuisId != null) { if (_gebruikerRepository.FindByUsername(model.GebruikersNaam) != null) { this.AddNotification("Er is al reeds iemand met deze gebruikersnaam", NotificationType.ERROR); return RedirectToAction("CreateClient"); } //var crypto = new SimpleCrypto.PBKDF2(); //var encrytwachtwoord = crypto.Compute(model.Wachtwoord); string pass = BCrypt.Net.BCrypt.HashPassword(model.Wachtwoord, BCrypt.Net.BCrypt.GenerateSalt()); var client = new Client(model.Naam, model.Voornaam, _opvangtehuisRepository.FindByName(model.GeselecteerdOpvangtehuisId), model.GebruikersNaam, pass); _gebruikerRepository.AddClient(client); _gebruikerRepository.SaveChanges(); if (_gebruikerRepository.FindById((int)Session["gebruiker"]) is Admin) { this.AddNotification("Cliënt toegevoegd", NotificationType.SUCCESS); return RedirectToAction("AdminIndex"); } this.AddNotification("Cliënt toegevoegd", NotificationType.SUCCESS); return RedirectToAction("OpvoederIndex"); } } catch (ApplicationException e) { ModelState.AddModelError("", e.Message); } } var ccvm = new GebruikerViewModel.CreateClientViewModel() { GebruikerType = _gebruikerRepository.FindById((int)Session["gebruiker"]).GetType().Name, Opvangtehuizen = _opvangtehuisRepository.FindAll().Select(oh => oh.Naam).ToList() }; return View(ccvm); }
public ActionResult CreateClient() { if (UserStillLoggedIn() || _gebruikerRepository.FindById((int)Session["gebruiker"]) is Client) { return ReturnToLogin(); } if (!Request.IsAuthenticated) { return View("Error"); } var ccvm = new GebruikerViewModel.CreateClientViewModel((_gebruikerRepository.FindById((int)Session["gebruiker"])).GetType().Name); if (_gebruikerRepository.FindById((int)Session["gebruiker"]) is Admin) { ccvm.SetOpvangtehuizen(_opvangtehuisRepository.FindAll().Select(oh => oh.Naam).ToList()); } else { ccvm.AddOpvangtehuis(_gebruikerRepository.FindById((int)Session["gebruiker"]).GetOpvangtehuisnaam()); } return View(ccvm); }