public async Task <IHttpActionResult> InviteFollowers(int id, ConfirmedAttendees usersToInvite) { var e = db.Events.Find(id); if (e != null) { foreach (string username in usersToInvite.Usernames) { var validUser = db.Users.Where(x => x.UserName.Equals(username, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (validUser != null) { if (e.EventInvitedGuests.Where(x => x.User == validUser).FirstOrDefault() == null) { e.EventInvitedGuests.Add(new InvitedUser() { User = validUser, InvitedUserId = Guid.NewGuid() }); db.SaveChanges(); await inviteNotifications(e, validUser); } } } } return(Ok()); }
public async Task <IHttpActionResult> ConfirmAttendance(int id, ConfirmedAttendees confirmed) { var e = db.Events.Find(id); if (e == null) { return(BadRequest()); } foreach (string u in confirmed.Usernames) { ApplicationUser attendee = null; if (e.ConfirmedGuests.Count > 0) { ConfirmedUser alreadyConfirmed = e.ConfirmedGuests.Where(x => x.User.UserName.Equals(u, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (alreadyConfirmed != null) { attendee = alreadyConfirmed.User; } } if (attendee == null) { ApplicationUser user = db.Users.FirstOrDefault(x => x.UserName.Equals(u, StringComparison.OrdinalIgnoreCase)); e.ConfirmedGuests.Add(new ConfirmedUser() { User = user, ConfirmedUserId = Guid.NewGuid() }); try { db.SaveChanges(); var myMessage = new SendGridMessage(); myMessage.From = new MailAddress("*****@*****.**"); myMessage.AddTo(string.Format(@"{0} <{1}>", user.UserName, user.Email)); myMessage.Subject = string.Format("Attendance confirmation for {0}", e.EventTitle); myMessage.Html = String.Format("<p>You have just been confirmed as attending by the host of {0}</p>", e.EventTitle); myMessage.Text = String.Format("You have just been confirmed as attending by the host of {0}", e.EventTitle); var apiKey = System.Environment.GetEnvironmentVariable("SENDGRID_APIKEY"); var transportWeb = new Web(apiKey); // Send the email. await transportWeb.DeliverAsync(myMessage); await PostNotification("gcm", String.Format("You have been confirmed as attending for {0}", e.EventTitle), user.Email); } catch (DbUpdateConcurrencyException) { if (!EventExists(id)) { return(NotFound()); } else { throw; } } } } return(Json(new { success = true })); }
public async Task<IHttpActionResult> ConfirmAttendance(int id, ConfirmedAttendees confirmed) { var e = db.Events.Find(id); if (e == null) { return BadRequest(); } foreach (string u in confirmed.Usernames) { ApplicationUser attendee = null; if (e.ConfirmedGuests.Count > 0) { ConfirmedUser alreadyConfirmed = e.ConfirmedGuests.Where(x => x.User.UserName.Equals(u, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if(alreadyConfirmed != null) { attendee = alreadyConfirmed.User; } } if (attendee == null) { ApplicationUser user = db.Users.FirstOrDefault(x => x.UserName.Equals(u, StringComparison.OrdinalIgnoreCase)); e.ConfirmedGuests.Add(new ConfirmedUser() { User = user, ConfirmedUserId = Guid.NewGuid()}); try { db.SaveChanges(); var myMessage = new SendGridMessage(); myMessage.From = new MailAddress("*****@*****.**"); myMessage.AddTo(string.Format(@"{0} <{1}>", user.UserName, user.Email)); myMessage.Subject = string.Format("Attendance confirmation for {0}", e.EventTitle); myMessage.Html = String.Format("<p>You have just been confirmed as attending by the host of {0}</p>", e.EventTitle); myMessage.Text = String.Format("You have just been confirmed as attending by the host of {0}", e.EventTitle); var apiKey = System.Environment.GetEnvironmentVariable("SENDGRID_APIKEY"); var transportWeb = new Web(apiKey); // Send the email. await transportWeb.DeliverAsync(myMessage); await PostNotification("gcm", String.Format("You have been confirmed as attending for {0}", e.EventTitle), user.Email); } catch (DbUpdateConcurrencyException) { if (!EventExists(id)) { return NotFound(); } else { throw; } } } } return Json(new { success = true }); }
public async Task<IHttpActionResult> InviteFollowers(int id, ConfirmedAttendees usersToInvite) { var e = db.Events.Find(id); if (e != null) { foreach (string username in usersToInvite.Usernames) { var validUser = db.Users.Where(x => x.UserName.Equals(username, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (validUser != null) { if (e.EventInvitedGuests.Where(x => x.User == validUser).FirstOrDefault() == null) { e.EventInvitedGuests.Add(new InvitedUser() { User = validUser, InvitedUserId = Guid.NewGuid()}); db.SaveChanges(); await inviteNotifications(e, validUser); } } } } return Ok(); }