public static void fnSendEmail(BulkOrderEmailViewModel obj) { // build table and send email var q = fnFillBulkOrderFromDB(obj.bulkorderid); System.Text.StringBuilder s = new System.Text.StringBuilder(); s.Append(String.Format("<p><em>The following message is sent on behalf of {0}</em></p>", obj.FromAddress)); s.Append("<p>Please send the following items:</p>"); s.Append("<table width='70%'><tr align='left'><th align='left'>Mastercode</th><th align='left'>Master Name</th><th align='left'>Weight</th></tr>"); foreach (var item in q.ListOfBulkOrderItem) { s.Append(String.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>", item.mastercode, item.mastername, item.weight)); } s.Append("</table>"); obj.MessageBody = s.ToString(); Thread.Sleep(500); ApplicationService.EmailSmtpSend(obj.FromAddress, obj.ToAddress, obj.Subject, obj.MessageBody); // update db with email timestamp using (var db = new EF.CMCSQL03Entities()) { var dbBulkOrder = db.tblBulkOrder.Find(obj.bulkorderid); dbBulkOrder.EmailSent = String.Format("{0:dd MMM yyyy HH:mm:ss}", DateTime.Now.ToString()); db.SaveChanges(); } }
public ActionResult Email(BulkOrderEmailViewModel obj) { ReplenishmentsService.fnSendEmail(obj); return RedirectToAction("Index"); }
public static BulkOrderEmailViewModel fnCreateEmail(BulkOrder vm) { BulkOrderEmailViewModel message = new BulkOrderEmailViewModel(); message.bulkorderid = vm.bulkorderid; message.clientname = vm.clientname; message.logofilename = vm.logofilename; message.ToAddress = vm.bulksupplieremail; message.FromAddress = HttpContext.Current.User.Identity.Name; message.Subject = "CMC Replenishment Order: " + vm.bulkorderid; var q = fnFillBulkOrderFromDB(vm.bulkorderid); System.Text.StringBuilder s = new System.Text.StringBuilder(); s.Append("<div class='table-responsive'><table class='table table-hover table-striped'><thead><tr><th>Mastercode</th><th>Master Name</th><th align='right'>Weight</th></tr></thead>"); foreach (var item in q.ListOfBulkOrderItem) { s.Append(String.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>", item.mastercode, item.mastername, item.weight)); } s.Append("</table></div>"); message.MessageBody = s.ToString(); return message; }