public ActionResult Public() { ViewBag.Title = "Extrait public du registre foncier"; // Let's get all states that we need for a DropDownList var communes = GetAllStates(); var model = new PublicViewModels(); // Create a list of SelectListItems so these can be rendered on the page model.Communes = GetSelectListItems(communes); return(View(model)); }
public ActionResult Public(PublicViewModels model) { // Get all states again var communes = GetAllStates(); // Set these states on the model. We need to do this because // only the selected value from the DropDownList is posted back, not the whole // list of states. model.Communes = GetSelectListItems(communes); // Increment the id Public Random rnd = new Random(); model.IdPublic = rnd.Next(1, 9999); // recovery of the ip address string hote = Dns.GetHostName(); IPHostEntry iphe = Dns.Resolve(hote); string ip = iphe.AddressList[0].ToString(); if (ModelState.IsValid) { Session["PublicViewModels"] = model; Boolean result = true; result = Logs.Logs.ReadLog(model.Email, ip); if (result == true) { PublicManager.GetExtraitPublic(model.IdPublic, model.Name, model.Firstname, model.Email, model.Commune, model.Parcelle); Logs.Logs.LogExtraitPublic(model.IdPublic + " - " + model.Name + " " + model.Firstname + ", Commune de " + model.Commune + " Parcelle n° " + model.Parcelle, model.Email, ip); ViewBag.Success = true; ViewBag.Message = "La demande a été transmise !"; return(RedirectToAction("Done")); } else { TempData["msg"] = "<script>alert('Vous avez atteint le nombre de demandes maximum. Revenez demain.');</script>"; return(View("Public", model)); } } else { ViewBag.Message = "Erreur dans la transmission de la demande !"; return(View("Public", model)); } }