public ActionResult Index(Identite identite, Structure structure, Choix choix) { if (!ModelState.IsValid) { return(View("Index")); } using (IDal dal = new Dal()) { int idPresta = dal.CreerPrestation(identite, structure, choix); if (idPresta == -1) { ViewBag.ActionErreur = "nouvelle demande de prestation"; return(RedirectToAction("Index")); } FormsAuthentication.SetAuthCookie("utilisateur" + idPresta, false); string message = dal.MailDemandePresta(idPresta); MailMessage email = new MailMessage(); email.To.Add(identite.Email); email.CC.Add("*****@*****.**"); email.From = new MailAddress("*****@*****.**"); email.Subject = "Demande de prestation Origin's Krew"; email.IsBodyHtml = true; email.Body = message; SmtpClient client = new SmtpClient("smtp.ionos.fr", 587); client.EnableSsl = true; NetworkCredential credential = new NetworkCredential("*****@*****.**", "SKL-63119-bgnt"); client.Credentials = credential; try { client.Send(email); } catch (Exception e) { Console.WriteLine("Erreur : " + e); } return(RedirectToAction("RecapDemande", "DemandePresta", new { id = idPresta })); } }
public int CreerPrestation(Identite identite, Structure structure, Choix choix) { try { bdd.Prestations.Add(new Prestation { DateCreation = DateTime.Now, Prenom = identite.Prenom, Nom = identite.Nom, Email = identite.Email, Telephone = identite.Telephone, Type = structure.Type, NomStructure = structure.NomStructure, Pays = structure.Pays, Etat = structure.Etat, VilleEU = structure.VilleEU, VilleAutre = structure.VilleAutre, CodePostal = structure.CodePostal, ChoixPrestation = choix.ChoixPrestation, TempsPresta = choix.TempsPresta, Occurence = choix.Occurence, Initiation = choix.Initiation, Budget = choix.Budget, Date = choix.Date, DureeStage = choix.DureeStage, Niveau = choix.Niveau, InfoComplementaire = choix.InfoComplementaire }); bdd.SaveChanges(); return(bdd.Prestations.ToList().ElementAt(bdd.Prestations.Count() - 1).Id); }catch (Exception e) { Utils.Logger.Log("ERROR", "Erreur création de prestation : " + e); return(-1); } }