private async Task EmailInvite(Invite invite) { // Create the email object first, then add the properties. var myMessage = new SendGridMessage(); // Add the message properties. myMessage.From = new MailAddress("*****@*****.**"); // Add multiple addresses to the To field. var recipients = new List<string> { invite.Email, }; myMessage.AddTo(recipients); myMessage.Subject = "Joinin Invite"; //var link = $"http://joinin.azurewebsites.net/AcceptInvite/{invite.Id}"; //Add the HTML and Text bodies myMessage.Text = "You should join in!"; var username = "******"; var pswd = "ipxspx123"; var credentials = new NetworkCredential(username, pswd); var transportWeb = new Web(credentials); try { await transportWeb.DeliverAsync(myMessage); } catch (Exception e) { Console.WriteLine(e); } }
public async Task Post(Invite invite) { using (var context = new ApplicationDbContext()) { string userName = $"User-{Guid.NewGuid()}"; var user = new ApplicationUser { UserName = userName, Email = invite.Email }; var result = Request.GetOwinContext() .GetUserManager<ApplicationUserManager>() .CreateAsync(user, Guid.NewGuid().ToString()).Result; if (!result.Succeeded) { throw new Exception("Error Inviting!"); } var createdUser = context.Users .Single(u => u.UserName == userName); invite.CreatedUser = createdUser; context.EventUsers.Add(new EventUser { EventId = invite.EventId, UserId = createdUser.Id, Owner = false, Attending = Attending.NotSelected, }); context.Invites .Add(invite); await EmailInvite(invite); context.SaveChanges(); } }