public ActionResult Update(FormCollection form, int id, HttpPostedFileBase foto) { if (!AuthRepository.CheckIfUserCanAcces(GebruikerType.All, (Gebruiker)Session["LoggedInUser"])) { return(View("~/Views/Error/AuthError.cshtml")); } try { if (Session["LoggedInUser"] != null) { Gebruiker loggedinGebruiker = Session["LoggedInUser"] as Gebruiker; GebruikerSqlContext sql = new GebruikerSqlContext(); GebruikerRepository repo = new GebruikerRepository(sql); VrijwilligerSqlContext vsql = new VrijwilligerSqlContext(); VrijwilligerRepository vrepo = new VrijwilligerRepository(vsql); Gebruiker gebruiker = new Gebruiker(); gebruiker.Id = id; string path = ""; string fotoPath = ""; if (foto != null) { if (foto.ContentLength > 0) { if (Path.GetExtension(foto.FileName).ToLower() == ".png" || Path.GetExtension(foto.FileName).ToLower() == ".jpg" || Path.GetExtension(foto.FileName).ToLower() == ".jpeg") { path = Path.Combine(Server.MapPath("~/Content/Foto"), foto.FileName); foto.SaveAs(path); fotoPath = "/Content/Foto/" + foto.FileName; gebruiker.Image = fotoPath; } } } else { gebruiker.Image = loggedinGebruiker.Image; } if (form["wachtwoord"] != "" && form["wachtwoordnieuw"] != "") { if (form["wachtwoord"] == form["wachtwoordnieuw"]) { gebruiker.Wachtwoord = form["wachtwoord"]; } } else { gebruiker.Wachtwoord = loggedinGebruiker.Wachtwoord; } gebruiker.Geslacht = (Geslacht)Enum.Parse(typeof(Geslacht), form["geslacht"]); gebruiker.Adres = form["adres"]; gebruiker.Email = form["email"]; gebruiker.Woonplaats = form["plaats"]; gebruiker.Land = form["land"]; gebruiker.Postcode = form["postcode"]; gebruiker.Telefoonnummer = form["telnr"]; gebruiker.Gebruikersnaam = form["gebruikersnaam"]; gebruiker.Naam = form["naam"]; gebruiker.HeeftAuto = Convert.ToBoolean(form["auto"]); gebruiker.HeeftRijbewijs = Convert.ToBoolean(form["rijbewijs"]); gebruiker.HeeftOv = Convert.ToBoolean(form["ov"]); gebruiker.Barcode = form["barcode"]; string[] vaardigheidIds = form.GetValues("vaardigheden"); List <int> vaardigheidIdList = new List <int>(); if (vaardigheidIds != null) { foreach (string vaardigheidId in vaardigheidIds) { vaardigheidIdList.Add(Convert.ToInt32(vaardigheidId)); } } if (vaardigheidIdList.Count != 0) { vrepo.CreateVrijwilligerWithVaardigheid(gebruiker.Id, vaardigheidIdList); } repo.Update(gebruiker); return(RedirectToAction("Gegevens", "Gebruiker", new { id = gebruiker.Id })); } return(RedirectToAction("Index", "Login")); } catch (Exception e) { return(RedirectToAction("Index", "Error")); } }
public ActionResult Save(FormCollection form, HttpPostedFileBase foto, HttpPostedFileBase vog) { try { string vogPath = ""; string path = ""; if (vog != null) { if (vog.ContentLength > 0) { if (Path.GetExtension(vog.FileName).ToLower() == ".pdf") { path = Path.Combine(Server.MapPath("~/Content/VOG"), vog.FileName); vog.SaveAs(path); vogPath = "/Content/VOG/" + vog.FileName; } } } string fotoPath = ""; if (foto != null) { if (foto.ContentLength > 0) { if (Path.GetExtension(foto.FileName).ToLower() == ".png" || Path.GetExtension(foto.FileName).ToLower() == ".jpg" || Path.GetExtension(foto.FileName).ToLower() == ".jpeg") { path = Path.Combine(Server.MapPath("~/Content/Foto"), foto.FileName); foto.SaveAs(path); fotoPath = "/Content/Foto/" + foto.FileName; } } } if (form["vrij"] == null && form["hulp"] == null) { return(RedirectToAction("Index", "Registreer")); } if (form["wachtwoord"] == form["wachtwoordherhalen"]) { Gebruiker gebruiker1 = new Gebruiker(); gebruiker1.Image = fotoPath; gebruiker1.Geslacht = (Geslacht)Enum.Parse(typeof(Geslacht), form["geslacht"]); gebruiker1.Adres = form["adres"]; gebruiker1.Email = form["email"]; gebruiker1.Geboortedatum = Convert.ToDateTime(form["geboortedatum"]); gebruiker1.Woonplaats = form["plaats"]; gebruiker1.Land = form["land"]; gebruiker1.Postcode = form["postcode"]; gebruiker1.Telefoonnummer = form["telnr"]; // gebruiker1.Huisnummer = form["huisnr"]; gebruiker1.Wachtwoord = form["wachtwoord"]; gebruiker1.Gebruikersnaam = form["gebruikersnaam"]; gebruiker1.Naam = form["naam"]; gebruiker1.HeeftAuto = bool.Parse(form["auto"]); gebruiker1.HeeftRijbewijs = bool.Parse(form["rijbewijs"]); gebruiker1.HeeftOv = bool.Parse(form["ov"]); gebruiker1.Barcode = form["barcode"]; string[] vaardigheidIds = form.GetValues("vaardigheden"); List <int> vaardigheidIdList = new List <int>(); if (vaardigheidIds != null) { foreach (string vaardigheidId in vaardigheidIds) { vaardigheidIdList.Add(Convert.ToInt32(vaardigheidId)); } } GebruikerSqlContext sql = new GebruikerSqlContext(); GebruikerRepository repo = new GebruikerRepository(sql); int id = repo.Create(gebruiker1); if (form["hulp"] != null && form["hulp"] == "hulpbehoevende") { Hulpbehoevende hulpbehoevende = new Hulpbehoevende(id); hulpbehoevende.Id = id; HulpbehoevendeSqlContext hsql = new HulpbehoevendeSqlContext(); HulpbehoevendeRepository hrepo = new HulpbehoevendeRepository(hsql); hrepo.CreateHulpbehoevende(hulpbehoevende.Id, hrepo.BepaalHulpverlener()); } if (form["vrij"] != null && form["vrij"] == "vrijwilliger") { Vrijwilliger vrijwilliger = new Vrijwilliger(id, vogPath, false); VrijwilligerSqlContext vsql = new VrijwilligerSqlContext(); VrijwilligerRepository vrepo = new VrijwilligerRepository(vsql); vrepo.Create(vrijwilliger.Id, vrijwilliger.VOG); if (vaardigheidIdList.Count != 0) { vrepo.CreateVrijwilligerWithVaardigheid(vrijwilliger.Id, vaardigheidIdList); } } return(RedirectToAction("Index", "Login")); } return(RedirectToAction("Index", "Registreer")); } catch (Exception e) { return(RedirectToAction("Index", "Error")); } }