//SendAfterClosingEmails public JsonExecuteResult SendAfterClosingEmails(long event_id) { bool iserror = false; try { Event evnt = GetEvent(event_id); if (evnt == null) return new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "Event doesn't exist in the database."); if (evnt.CloseStep != 2) throw new Exception("This event is not closed"); EndOfAuction eoa; StringBuilder sb = new StringBuilder(); sb.AppendLine("Emails already sent to users:"); dataContext.CommandTimeout = 6000000; foreach (var user in dataContext.spUser_GetBiddersForEventClose(event_id).ToList()) { try { eoa = new EndOfAuction(); eoa.EventTitle = evnt.Title; eoa.UserName = String.Format("{0} {1}{2}", user.FirstName, String.IsNullOrEmpty(user.MiddleName) ? String.Empty : user.MiddleName + " ", user.LastName); eoa.Invoices.AddRange( (from p in dataContext.spInvoice_Detail_UserUnpaid(user.ID, event_id) where p.Event_ID == event_id select new InvoiceDetail { Auction_ID = p.Auction_ID, Cost = p.Cost, Invoice_ID = p.Invoice_ID, LateFee = p.LateFee, LinkParams = new LinkParams { ID = p.Auction_ID, Lot = p.Lot.GetValueOrDefault(0), Title = p.Title, Event_ID = p.Event_ID, EventTitle = p.EventTitle, EventCategory_ID = p.EventCategory_ID, CategoryTitle = p.Category }, Lot = p.Lot.GetValueOrDefault(0), SaleDate = p.DateCreated, Shipping = p.Shipping, Tax = p.Tax, Title = p.Title, UserInvoice_ID = p.UserInvoices_ID.GetValueOrDefault(0) }).ToList()); eoa.LoserLots.AddRange((from p in dataContext.spBid_View_BidWatch(user.ID, event_id) where p.IsWatch.GetValueOrDefault(0) == 0 select new UserBidWatch { Amount = p.Amount.GetValueOrDefault(0), Quantity = p.Quantity, MaxBid = p.MaxBid.GetValueOrDefault(0), Option = p.IsWatch.GetValueOrDefault(0), LinkParams = new LinkParams { ID = p.Auction_ID, Lot = p.Lot.GetValueOrDefault(0), Title = p.Title, EventTitle = p.EventTitle, CategoryTitle = p.CategoryTitle }, Bids = p.Bids.GetValueOrDefault(0), CurrentBid = p.CurrentBid.GetValueOrDefault(0), HighBidder = p.HighBidder }).ToList()); Mail.SendEndOfAuctionHTMLLetter(user.Email, eoa); sb.AppendLine(user.Email); } catch (Exception ex) { iserror = true; Logger.LogException("Winner email to user " + user.Login + " failed : " + ex.Message + " (" + ex.StackTrace + ")", ex); } } Logger.LogInfo(sb.ToString()); //Event current = GetEvent(event_id); //if (current == null) return new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "Event doesn't exist in the database."); //if (current.CloseStep != 2) throw new Exception("This event is not closed"); //List<Auction> allAuctions = ( // from A in dataContext.Auctions // where A.Event_ID == current.ID && A.Status == (byte)Consts.AuctionStatus.Closed && A.Bids.Count > 0 // orderby A.Lot.Value ascending // select A).ToList(); //User user; //sp_GetAuctionWinnerTableResult bid; //List<sp_GetAuctionWinnerTableResult> bids; //foreach (Auction auc in allAuctions) //{ // bid = dataContext.sp_GetAuctionWinnerTable(auc.ID, 1).FirstOrDefault(); // user = dataContext.Users.SingleOrDefault(U => U.ID == bid.User_ID); // if ((auc.Reserve.HasValue && auc.Reserve.Value > bid.Amount) || (user.UserType_ID != (byte)Consts.UserTypes.Buyer && user.UserType_ID != (byte)Consts.UserTypes.SellerBuyer) || String.IsNullOrEmpty(user.Email)) continue; // if (user == null || !user.IsRecievingLotClosedNotice || String.IsNullOrEmpty(user.Email)) continue; // try // { // Mail.SendWinningLetter(user.AddressCard_Billing.FirstName, user.AddressCard_Billing.LastName, user.Email, (long)auc.Lot.Value, auc.Title, bid.Amount.GetCurrency()); // } // catch (Exception ex) // { // Logger.LogInfo("Winner email to user " + user.Login + " failed : " + ex.Message); // } // if (auc.Bids.Count == 1) continue; // bids = dataContext.sp_GetAuctionWinnerTable(auc.ID, 0).ToList(); // foreach (var winbid in bids) // { // bid = winbid; // user = dataContext.Users.SingleOrDefault(U => U.ID == bid.User_ID); // if ((user.UserType_ID != (byte)Consts.UserTypes.Buyer && user.UserType_ID != (byte)Consts.UserTypes.SellerBuyer) || String.IsNullOrEmpty(user.Email)) continue; // if (user == null || !user.IsRecievingLotSoldNotice || String.IsNullOrEmpty(user.Email)) continue; // try // { // Mail.SendEndOfAuctionLetter(user.Email, (long)auc.Lot.Value, auc.Title); // } // catch (Exception ex) // { // Logger.LogInfo("Winner email to user " + user.Login + " failed : " + ex.Message); // } // } //} } catch (Exception ex) { return new JsonExecuteResult(JsonExecuteResultTypes.ERROR, ex.Message); } return new JsonExecuteResult(JsonExecuteResultTypes.SUCCESS, "The event was closed successfuly! " + (iserror ? "(Note: watch the log file for details)" : String.Empty)); }
//SendAfterClosingEmails public JsonExecuteResult SendAfterClosingEmails(long event_id) { bool iserror = false; try { Event evnt = GetEvent(event_id); if (evnt == null) { return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "Event doesn't exist in the database.")); } if (evnt.CloseStep != 2) { throw new Exception("This event is not closed"); } EndOfAuction eoa; StringBuilder sb = new StringBuilder(); sb.AppendLine("Emails already sent to users:"); dataContext.CommandTimeout = 6000000; foreach (var user in dataContext.spUser_GetBiddersForEventClose(event_id).ToList()) { try { eoa = new EndOfAuction(); eoa.EventTitle = evnt.Title; eoa.UserName = String.Format("{0} {1}{2}", user.FirstName, String.IsNullOrEmpty(user.MiddleName) ? String.Empty : user.MiddleName + " ", user.LastName); eoa.Invoices.AddRange( (from p in dataContext.spInvoice_Detail_UserUnpaid(user.ID, event_id) where p.Event_ID == event_id select new InvoiceDetail { Auction_ID = p.Auction_ID, Cost = p.Cost, Invoice_ID = p.Invoice_ID, LateFee = p.LateFee, LinkParams = new LinkParams { ID = p.Auction_ID, Lot = p.Lot.GetValueOrDefault(0), Title = p.Title, Event_ID = p.Event_ID, EventTitle = p.EventTitle, EventCategory_ID = p.EventCategory_ID, CategoryTitle = p.Category }, Lot = p.Lot.GetValueOrDefault(0), SaleDate = p.DateCreated, Shipping = p.Shipping, Tax = p.Tax, Title = p.Title, UserInvoice_ID = p.UserInvoices_ID.GetValueOrDefault(0) }).ToList()); eoa.LoserLots.AddRange((from p in dataContext.spBid_View_BidWatch(user.ID, event_id) where p.IsWatch.GetValueOrDefault(0) == 0 select new UserBidWatch { Amount = p.Amount.GetValueOrDefault(0), Quantity = p.Quantity, MaxBid = p.MaxBid.GetValueOrDefault(0), Option = p.IsWatch.GetValueOrDefault(0), LinkParams = new LinkParams { ID = p.Auction_ID, Lot = p.Lot.GetValueOrDefault(0), Title = p.Title, EventTitle = p.EventTitle, CategoryTitle = p.CategoryTitle }, Bids = p.Bids.GetValueOrDefault(0), CurrentBid = p.CurrentBid.GetValueOrDefault(0), HighBidder = p.HighBidder }).ToList()); Mail.SendEndOfAuctionHTMLLetter(user.Email, eoa); sb.AppendLine(user.Email); } catch (Exception ex) { iserror = true; Logger.LogException("Winner email to user " + user.Login + " failed : " + ex.Message + " (" + ex.StackTrace + ")", ex); } } Logger.LogInfo(sb.ToString()); //Event current = GetEvent(event_id); //if (current == null) return new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "Event doesn't exist in the database."); //if (current.CloseStep != 2) throw new Exception("This event is not closed"); //List<Auction> allAuctions = ( // from A in dataContext.Auctions // where A.Event_ID == current.ID && A.Status == (byte)Consts.AuctionStatus.Closed && A.Bids.Count > 0 // orderby A.Lot.Value ascending // select A).ToList(); //User user; //sp_GetAuctionWinnerTableResult bid; //List<sp_GetAuctionWinnerTableResult> bids; //foreach (Auction auc in allAuctions) //{ // bid = dataContext.sp_GetAuctionWinnerTable(auc.ID, 1).FirstOrDefault(); // user = dataContext.Users.SingleOrDefault(U => U.ID == bid.User_ID); // if ((auc.Reserve.HasValue && auc.Reserve.Value > bid.Amount) || (user.UserType_ID != (byte)Consts.UserTypes.Buyer && user.UserType_ID != (byte)Consts.UserTypes.SellerBuyer) || String.IsNullOrEmpty(user.Email)) continue; // if (user == null || !user.IsRecievingLotClosedNotice || String.IsNullOrEmpty(user.Email)) continue; // try // { // Mail.SendWinningLetter(user.AddressCard_Billing.FirstName, user.AddressCard_Billing.LastName, user.Email, (long)auc.Lot.Value, auc.Title, bid.Amount.GetCurrency()); // } // catch (Exception ex) // { // Logger.LogInfo("Winner email to user " + user.Login + " failed : " + ex.Message); // } // if (auc.Bids.Count == 1) continue; // bids = dataContext.sp_GetAuctionWinnerTable(auc.ID, 0).ToList(); // foreach (var winbid in bids) // { // bid = winbid; // user = dataContext.Users.SingleOrDefault(U => U.ID == bid.User_ID); // if ((user.UserType_ID != (byte)Consts.UserTypes.Buyer && user.UserType_ID != (byte)Consts.UserTypes.SellerBuyer) || String.IsNullOrEmpty(user.Email)) continue; // if (user == null || !user.IsRecievingLotSoldNotice || String.IsNullOrEmpty(user.Email)) continue; // try // { // Mail.SendEndOfAuctionLetter(user.Email, (long)auc.Lot.Value, auc.Title); // } // catch (Exception ex) // { // Logger.LogInfo("Winner email to user " + user.Login + " failed : " + ex.Message); // } // } //} } catch (Exception ex) { return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, ex.Message)); } return(new JsonExecuteResult(JsonExecuteResultTypes.SUCCESS, "The event was closed successfuly! " + (iserror ? "(Note: watch the log file for details)" : String.Empty))); }
//SendEndOfAuctionHTMLLetter public static void SendEndOfAuctionHTMLLetter(string email, EndOfAuction eoa) { UniMail.Template template = new UniMail.Template(HttpContext.Current.Server.MapPath(@"~\Templates\Mail\EndOfAuctionNoticeHTML.txt"), "mail"); string emailTitle = (eoa.Invoices.Count() > 0 ? "Winning Auction Notification for " : "End of Auction Notice for ") + eoa.EventTitle; template.Subject = emailTitle; template.Encoding = Encoding.UTF8; template.ToEmail = email; template.Data.Add("{{email_subject}}", emailTitle); template.Data.Add("{{email_title}}", eoa.Invoices.Count() > 0 ? "Congratulations!" : emailTitle); if (eoa.Invoices.Count() > 0) template.Data.Add("{{email_title_2}}", eoa.UserName + ",<br />" + String.Format("Please send your payment to:<br />Lelands Collectibles, Inc.<br /> 130 Knickerbocker Avenue<br /> Suite E <br />Bohemia, NY 11716 <br /><br />International winners please contact [email protected] before sending payment to receive your international shipping cost. <br /><br />You can also preview your invoice online in your account or follow <a style='font-weight:bold;color:#6C0202' href='{2}/Account/InvoiceDetailed/{0}/{1}'>this link</a>.", eoa.Invoices.First().UserInvoice_ID, eoa.Invoices.First().LinkParams.EventUrl, "{{siteUrl}}") + "<br /><br />You are the winning bidder for the following auction item(s)."); else template.Data.Add("{{email_title_2}}", "This email is sent as a courtesy to let you know that this auction has ended."); StringBuilder table; if (eoa.Invoices.Count() > 0) { #region Invoices table = new StringBuilder(); table.AppendLine("<span style='color:#490202'><strong>Winning Item Invoice</strong></span>"); table.AppendLine("<table style='table-layout:fixed;font-size:12px;' cellpadding='0' cellspacing='0' >"); table.AppendLine("<colgroup><col width='80px' /><col width='510px' /><col width='140px' /></colgroup>"); table.AppendLine("<tr>"); table.AppendLine("<td style='font-weight:bold;background-color:#6C0202;color:#FFFFFF;padding: 5px 0px 5px 10px;font-size:12px;'>Lot#</td>"); table.AppendLine("<td style='font-weight:bold;background-color:#6C0202;color:#FFFFFF;padding: 5px 0px 5px 10px;font-size:12px;'>Title</td>"); table.AppendLine("<td style='font-weight:bold;background-color:#6C0202;color:#FFFFFF;padding: 5px 0px 5px 10px;font-size:12px;'>Cost</td>"); table.AppendLine("</tr>"); foreach (InvoiceDetail invoice in eoa.Invoices) { table.AppendLine("<tr>"); table.AppendFormat("<td style='font-size:12px;font-weight:bold;padding: 5px 0px 5px 10px;background-color:#f4f4f4;border: solid 1px #e2e2e2'>{0}</td>", invoice.LinkParams.Lot); table.AppendFormat("<td style='font-size:12px;font-weight:bold;padding: 5px 0px 5px 10px;background-color:#f4f4f4;border: solid 1px #e2e2e2'>{0}</td>", invoice.LinkParams.Title); table.AppendFormat("<td style='font-size:12px;font-weight:bold;padding: 5px 0px 5px 10px;background-color:#f4f4f4;border: solid 1px #e2e2e2'>{0}</td>", invoice.Cost.GetCurrency()); table.AppendLine("</tr>"); } table.AppendFormat("<tr><td style='font-weight:bold;color:#490202;padding: 5px 5px 5px 10px; text-align:right;font-size:12px;' colspan='2'>{0}: </td><td style='font-weight:bold;color:#222;padding: 5px 0px 5px 10px;font-size:12px;background-color:#f4f4f4;border: solid 1px #e2e2e2'>{1}</td></tr>", "Net Cost*", eoa.TotalCst.GetCurrency(false)); table.AppendFormat("<tr><td style='font-weight:bold;color:#490202;padding: 5px 5px 5px 10px; text-align:right;font-size:12px;' colspan='2'>{0}: </td><td style='font-weight:bold;color:#222;padding: 5px 0px 5px 10px;font-size:12px;background-color:#f4f4f4;border: solid 1px #e2e2e2'>{1}</td></tr>", "Shipping, Handiling & Insurance", eoa.TotalShippingString); table.AppendFormat("<tr><td style='font-weight:bold;color:#490202;padding: 5px 5px 5px 10px; text-align:right;font-size:12px;' colspan='2'>{0}: </td><td style='font-weight:bold;color:#222;padding: 5px 0px 5px 10px;font-size:12px;background-color:#f4f4f4;border: solid 1px #e2e2e2'>{1}</td></tr>", "Sales Tax", eoa.TotalTax.GetCurrency(false)); table.AppendFormat("<tr><td style='font-weight:bold;color:#490202;padding: 5px 5px 5px 10px; text-align:right;font-size:12px;' colspan='2'>{0}: </td><td style='font-weight:bold;color:#222;padding: 5px 0px 5px 10px;font-size:12px;background-color:#f4f4f4;border: solid 1px #e2e2e2'>{1}</td></tr>", "Late Fees", eoa.TotalLateFee.GetCurrency(false)); table.AppendFormat("<tr><td style='font-weight:bold;color:#490202;padding: 5px 5px 5px 10px; text-align:right;font-size:12px;' colspan='2'>{0}: </td><td style='font-weight:bold;color:#222;padding: 5px 0px 5px 10px;font-size:12px;background-color:#f4f4f4;border: solid 1px #e2e2e2'>{1}</td></tr>", "Total Due", eoa.TotalCostString); table.AppendLine("</table>* Auction items include premium"); template.Data.Add("{{invoices_info}}", table.ToString()); #endregion } else template.Data.Add("{{invoices_info}}", String.Empty); template.Data.Add("{{separator}}", (eoa.Invoices.Count() > 0 && eoa.LoserLots.Count() > 0) ? "<br /><hr /><br />" : String.Empty); if (eoa.LoserLots.Count() > 0) { table = new StringBuilder(); table.AppendLine("<p>Unfortunately, you were not a successful bidder for lot(s)</p>"); table.AppendLine("<table style='table-layout:fixed;font-size:14px' cellpadding='0' cellspacing='0' >"); table.AppendLine("<colgroup><col width='80px' /><col width='290px' /><col width='100px' /><col width='100px' /><col width='100px' /><col width='60px' /></colgroup>"); table.AppendLine("<tr>"); table.AppendLine("<td style='font-weight:bold;background-color:#6C0202;color:#FFFFFF;padding: 5px 0px 5px 10px;font-size:12px;'>Lot#</td>"); table.AppendLine("<td style='font-weight:bold;background-color:#6C0202;color:#FFFFFF;padding: 5px 0px 5px 10px;font-size:12px;'>Title</td>"); table.AppendLine("<td style='font-weight:bold;background-color:#6C0202;color:#FFFFFF;padding: 5px 0px 5px 10px;font-size:12px;'>Winning Bid</td>"); table.AppendLine("<td style='font-weight:bold;background-color:#6C0202;color:#FFFFFF;padding: 5px 0px 5px 10px;font-size:12px;'>Your Bid</td>"); table.AppendLine("<td style='font-weight:bold;background-color:#6C0202;color:#FFFFFF;padding: 5px 0px 5px 10px;font-size:12px;'>Your MaxBid</td>"); table.AppendLine("<td style='font-weight:bold;background-color:#6C0202;color:#FFFFFF;padding: 5px 0px 5px 10px;font-size:12px;'>Bids</td>"); table.AppendLine("</tr>"); foreach (UserBidWatch ubw in eoa.LoserLots) { table.AppendLine("<tr>"); table.AppendLine("<td style='font-size:12px;font-weight:bold;padding: 5px 0px 5px 10px;background-color:#f4f4f4;border: solid 1px #e2e2e2'>" + ubw.LinkParams.Lot + "</td>"); table.AppendLine("<td style='font-size:12px;font-weight:bold;padding: 5px 0px 5px 10px;background-color:#f4f4f4;border: solid 1px #e2e2e2'>" + ubw.LinkParams.Title + "</td>"); table.AppendLine("<td style='font-size:12px;font-weight:bold;padding: 5px 0px 5px 10px;background-color:#f4f4f4;border: solid 1px #e2e2e2'>" + ubw.CurrentBid.GetCurrency() + "</td>"); table.AppendLine("<td style='font-size:12px;font-weight:bold;padding: 5px 0px 5px 10px;background-color:#f4f4f4;border: solid 1px #e2e2e2'>" + ubw.Amount.GetCurrency() + "</td>"); table.AppendLine("<td style='font-size:12px;font-weight:bold;padding: 5px 0px 5px 10px;background-color:#f4f4f4;border: solid 1px #e2e2e2'>" + ubw.MaxBid.GetCurrency() + "</td>"); table.AppendLine("<td style='font-size:12px;font-weight:bold;padding: 5px 0px 5px 10px;background-color:#f4f4f4;border: solid 1px #e2e2e2'>" + ubw.Bids + "</td>"); table.AppendLine("</tr>"); } table.AppendLine("</table><br />"); template.Data.Add("{{loserlots}}", table.ToString()); } else template.Data.Add("{{loserlots}}", String.Empty); ParseCommonData(template); UniMail.Mailer.Enqueue(template.RenderHTML(), "mail"); }