public async Task<IHttpActionResult> AddInvitationToProject(invitations invitations, int projectId) { if (!ModelState.IsValid) { return BadRequest(); } invitations.Project_FK = projectId; invitations.urlcode = RandomString(20); db.invitations.Add(invitations); await db.SaveChangesAsync(); sendMail(invitations); return Ok(invitations); }
public async Task<HttpResponseMessage> Postinvitations(invitations[] invitations, int projectId) { List<invitations> creationFailedInvitations = new List<invitations>(); foreach (invitations invitation in invitations) { if (_repo.checkForAvailableEmail(invitation.email)) creationFailedInvitations.Add(invitation); else { invitation.Project_FK = projectId; invitation.urlcode = RandomString(20); sendMail(invitation); db.invitations.Add(invitation); } } await db.SaveChangesAsync(); return Request.CreateResponse(HttpStatusCode.BadRequest, creationFailedInvitations); }
private void sendMail(invitations inv) { MailMessage mailMessage = new MailMessage("*****@*****.**", "*****@*****.**"); mailMessage.Subject = "Yout got invited to Pdmsys! Check it out!"; mailMessage.Body = "<body> Hello " + inv.firstname + " " + inv.lastname + "," + "<br> You have been invited to a project on Pdmsys, register yourself <a href = 'http://localhost:8080/pdmsys/#/invitation/'"+ inv.urlcode +">" + "here </a> and check your project out. If the link is not working, please copy http://localhost:8080/pdmsys/#/invitation/"+ inv.urlcode+" manually into your browser." + "<br>Kind Regards<br>Pdmsys - Admin</body>"; mailMessage.IsBodyHtml = true; SmtpClient smtpClient = new SmtpClient("smtp.mailgun.com", 587); smtpClient.Credentials = new System.Net.NetworkCredential() { UserName = "******", Password = "******" }; smtpClient.Send(mailMessage); }