public IHttpActionResult PostMandateModel(Mandate mandate) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //db.MandateModels.Add(mandateModel); sm.AddMandate(mandate); //catch (DbUpdateException) //{ // if (MandateModelExists(mandateModel.IdResource)) // { // return Conflict(); // } // else // { // throw; // } //} return(CreatedAtRoute("DefaultApi", new { id = mandate.IdResource }, mandate)); }
public ActionResult Create([Bind(Include = "IdResource,IdProject,MandateId,StartDate,EndDate,Fees")] MandateModel mandateModel) { if (ModelState.IsValid) { Mandate m = new Mandate() { MandateId = mandateModel.MandateId, IdMandateHistory = 1, EndDate = mandateModel.EndDate, Fees = CalculFees(mandateModel, mandateModel.IdResource), IdProject = mandateModel.IdProject, IdResource = mandateModel.IdResource, StartDate = mandateModel.StartDate, Disponibility = mandateModel.Disponibility }; s.AddMandate(m); //db.MandateModels.Add(mandateModel); s.Commit(); //MailMessage mail = new MailMessage("*****@*****.**", "*****@*****.**"); //SmtpClient client = new SmtpClient(); //client.Credentials = new NetworkCredential("*****@*****.**", "Espritsabrine100"); //client.Port = 25; //client.DeliveryMethod = SmtpDeliveryMethod.Network; //client.UseDefaultCredentials = false; //client.Host = "smtp.gmail.com"; //mail.Subject = "this is a test email."; //mail.Body = "this is my test email body"; //client.Send(mail); var req = from p in si.GetMany() where p.Id == mandateModel.IdResource select p; var r = req.FirstOrDefault(); MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); mail.From = new MailAddress("*****@*****.**"); mail.To.Add(r.Email); mail.Subject = "Assignment to a mandate"; mail.IsBodyHtml = true; mail.Body = "<div style='width:80%;margin-left:10%;border:1.5px solid #1b1a19;border-radius:7px;background:-moz-linear-gradient(top,white 0%,white 55%,#d5e4f3 130%)'>" + "<img src = 'https://scontent.ftun6-1.fna.fbcdn.net/v/t1.0-1/p720x720/17629739_661947114149166_6086201923177778760_n.png?_nc_cat=103&_nc_ht=scontent.ftun6-1.fna&oh=b248a78916f16409356bdba4cf746f01&oe=5C73CBC5' style = 'width:40%;height:250;margin-left:5%' class='CToWUd'>" + "<div style = 'margin-left:7%' >" + "<h3> Welcome " + r.FirstName + " " + r.LastName + ",</h3>" + "<p>You are assigned to a new mandate, please check your account</p>" + "<h3>Mandate details :</h3>" + "<table>" + "<tbody>" + " <tr><td><b>Start date :</b></td><td>" + mandateModel.StartDate + "</td></tr>" + "<tr><td><b>End date:</b></td><td>" + mandateModel.EndDate + "</td></tr>" + " </tbody>" + " </table>" + " <p>" + " You can access to our website : <a href = 'https://www.levio.ca' style= 'color:#253c93;text-decoration:none' > www.levio.ca </a>" + "</p> " + "</div>" + "</div> "; SmtpServer.Port = 25; SmtpServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "Espritsabrine100"); SmtpServer.EnableSsl = true; SmtpServer.Send(mail); return(RedirectToAction("Index")); } // return(View(mandateModel)); }