public async Task <ActionResult> Create([Bind(Include = "Id,Name,EmailId,GuidId,SendDate")] SendInvitation sendInvitation) { if (ModelState.IsValid && User.Identity.IsAuthenticated) { var url = System.Configuration.ConfigurationManager.AppSettings.Get("RegisterUrl"); var model = sendInvitation; // Create Guid model.GuidId = Guid.NewGuid().ToString(); // Create Date time stamp model.SendDate = DateTime.Now; string html = RenderViewToString(ControllerContext, "~/views/SendInvitations/NotificationEmail.cshtml", model, true); ViewBag.RenderedHtml = html; // Send email invitation to Subscriber through SMTP try { System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(System.Configuration.ConfigurationManager.AppSettings.Get("SmtpServer")); System.Net.Mail.MailAddress from = new System.Net.Mail.MailAddress(User.Identity.Name, User.Identity.Name, System.Text.Encoding.UTF8); // Set destinations for the e-mail message. System.Net.Mail.MailAddress to = new System.Net.Mail.MailAddress(sendInvitation.EmailId.ToString()); // Specify the message content. System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(from, to); // Insert message Body here. message.Body = html; // Include some non-ASCII characters in body and subject. string someArrows = new string(new char[] { '\u2190', '\u2191', '\u2192', '\u2193' }); message.Body += Environment.NewLine + someArrows; message.BodyEncoding = System.Text.Encoding.UTF8; message.Subject = "Invitation from ACME" + someArrows; message.SubjectEncoding = System.Text.Encoding.UTF8; // Set the method that is called back when the send operation ends. // client.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback); string userState = "Invitation"; client.SendAsync(message, userState); } catch (Exception Ex) { } db.SendInvitations.Add(sendInvitation); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(sendInvitation)); }
public async Task <ActionResult> DeleteConfirmed(int id) { SendInvitation sendInvitation = await db.SendInvitations.FindAsync(id); db.SendInvitations.Remove(sendInvitation); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Name,EmailId,GuidId,SendDate")] SendInvitation sendInvitation) { if (ModelState.IsValid && User.Identity.IsAuthenticated) { db.Entry(sendInvitation).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(sendInvitation)); }
// GET: SendInvitations/Details/5 public async Task <ActionResult> Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SendInvitation sendInvitation = await db.SendInvitations.FindAsync(id); if (sendInvitation == null) { return(HttpNotFound()); } return(View(sendInvitation)); }
public IHttpActionResult SendInvitation([FromBody] SendInvitation model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = BAL.GetUserByEmail(model.Email); if (user == null) { return(BadRequest("user not found")); } BAL.SendInvitation(user.Token, "i-table", $"invitation from {model.UserName}", model.GameID); return(Ok("invitation sent")); }
public async Task <IActionResult> SendInvitaion(Guid listId, [FromBody] SendInvitationViewModel invitation) { var senderAccountId = User.ReadClaimAsGuidValue("urn:codefliptodo:accountid"); var senderEmail = User.FindFirst(c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress").Value; var command = new SendInvitation() { SenderAccountId = senderAccountId, SenderEmail = senderEmail, ListId = listId, InviteeEmail = invitation.Email }; var response = await _mediator.Send(command); if (response == true) { return(Ok()); } return(BadRequest()); }