private string BuildTextTemplate(RaffleOrder order) { var text = $"Dart for Dreams - Raffle Receipt" + Environment.NewLine; text += $"{order.Customer.FirstName} {order.Customer.LastName}" + Environment.NewLine; text += $"{order.Customer.PhoneNumber} " + Environment.NewLine; text += $"{order.Customer.Email}" + Environment.NewLine; text += $"{order.Customer.AddressLine1}" + Environment.NewLine; text += $"{order.Customer.AddressLine2}" + Environment.NewLine; text += $"{order.Customer.City}, {order.Customer.State} {order.Customer.Zip}" + Environment.NewLine; text += $"" + Environment.NewLine + Environment.NewLine; foreach (var line in order.Lines) { text += $"{line.Name} {line.Price}p x {line.Count}tix" + Environment.NewLine; } text += Environment.NewLine; text += $"TOTAL POINTS: {order.TotalPrice}" + Environment.NewLine; text += Environment.NewLine + Environment.NewLine; text += "To complete the order please go to" + Environment.NewLine + "http://site.wish.org/goto/DartsforDreams15" + Environment.NewLine + $"and enter a donation for ${order.TotalPrice} to complete the purchase." + Environment.NewLine; return(text); }
private async Task SendCustomerReceiptEmail(RaffleOrder order, string body, string text) { await emailSender.SendEmailAsync( order.Customer.Email, $"{order.Customer.FirstName} {order.Customer.LastName}", $"Receipt for Darts For Dreams 15 Raffle Order# {order.Id}", text, body); }
private async Task SendOrderReceivedEmail(RaffleOrder order, string body, string text) { await emailSender.SendEmailAsync( managerEmail.Email, managerEmail.Name, $"Receipt for Darts For Dreams 15 Raffle Order# {order.Id}", text, body); }
private static RaffleOrderUpdateViewModel MapOrderModel( int id, IReadOnlyList <RaffleItem> items, RaffleOrder order) { var model = new RaffleOrderUpdateViewModel { Id = id, TicketNumber = order.TicketNumber, CompleteDate = order.CompletedDate.Value.ToUniversalTime(), Confirmed21 = order.Confirmed21, UpdateDate = order.UpdatedDate.HasValue ? order.UpdatedDate.Value.ToUniversalTime() : order.UpdatedDate, DonationDate = order.DonationDate, DonationNote = order.DonationNote, TotalPrice = order.TotalPrice, TotalTickets = order.TotalTickets, TotalTicketsFromSheet = order.TotalTicketsFromSheet, TotalTicketsOne = order.TotalOneTickets, TotalTicketsTwo = order.TotalTwoTickets, HowDidYouHear = order.HowDidYouHear, HOwDidYouHearOther = order.HowDidYouHearOther }; model.Customer = new RaffleOrderUpdateCustomer { FirstName = order.Customer.FirstName, LastName = order.Customer.LastName, Email = order.Customer.Email, PhoneNumber = order.Customer.PhoneNumber, AddressLine1 = order.Customer.AddressLine1, AddressLine2 = order.Customer.AddressLine2, City = order.Customer.City, State = order.Customer.State, Zip = order.Customer.Zip, IsInternational = order.Customer.IsInternational, InternationalAddress = order.Customer.InternationalAddress }; model.Lines = order.Lines.Select(x => new RaffleOrderUpdateLineModel { RaffleItemId = x.RaffleItemId, Amount = x.Count, Price = x.Price, Name = x.Name, ImageUrls = items.First(i => i.Id == x.RaffleItemId).ImageUrls }).ToList(); return(model); }
private string BuildTemplate(string template, RaffleOrder order) { const string token = "${privacy.url}"; var ticketDetail = ""; foreach (var line in order.Lines) { ticketDetail += "<tr>" + "<td style=\"font-family:'Open Sans', Arial, sans-serif; font-size:18px; line-height:22px; color: #fbeb59; letter-spacing:2px; padding-bottom:12px;\" valign=\"top\" align=\"left\" width=\"70%\">" + $"{line.Name}" + "</td>" + "<td style=\"font-family:'Open Sans', Arial, sans-serif; font-size:18px; line-height:22px; color: #fbeb59; letter-spacing:2px; padding-bottom:12px;\" valign=\"top\" align=\"center\">" + $"{line.Price} p" + "</td>" + "<td style=\"font-family:'Open Sans', Arial, sans-serif; font-size:18px; line-height:22px; color: #fbeb59; letter-spacing:2px; padding-bottom:12px;\" valign=\"top\" align=\"center\">" + $"{line.Count} tix" + "</td>" + "</tr>"; } var result = template.Replace(token, $"https://raffle.dartsfordreams.com/home/privacy") .Replace("${raffle.orderid}", order.Id.ToString()) .Replace("${donor.email}", order.Customer.Email) .Replace("${name.first}", order.Customer.FirstName) .Replace("${name.last}", order.Customer.LastName) .Replace("${phoneNumber}", order.Customer.PhoneNumber) .Replace("${address.line1}", order.Customer.AddressLine1) .Replace("${address.line2}", order.Customer.AddressLine2) .Replace("${raffle.tickets}", ticketDetail) .Replace("${raffle.price}", order.TotalPrice.ToString()); if (order.Customer.IsInternational) { result = result.Replace("${address.city_state_zip}", order.Customer.InternationalAddress.Replace("\r\n", "<br />")); } else { result = result.Replace("${address.city_state_zip}", $"{order.Customer.City}, {order.Customer.State} {order.Customer.Zip}"); } return(result); }
public async Task <IActionResult> Index(string sortBy, string searchFilter, string categoryFilter) { var raffleEvent = raffleEventRepository.GetById(1); if (raffleEvent.CloseDate.HasValue && raffleEvent.CloseDate.Value < DateTime.UtcNow) { return(View("IndexRaffleClosed")); } RaffleOrder order = null; if (HttpContext.Request.Cookies.ContainsKey(CookieKeys.RaffleOrderId)) { int.TryParse(HttpContext.Request.Cookies[CookieKeys.RaffleOrderId], out int orderId); if (!(await mediator.Send(new RaffleOrderExistsQuery { OrderId = orderId }))) { logger.LogInformation("No Order Found"); orderId = await mediator.Send(new StartRaffleOrderQuery()); HttpContext.Response.Cookies.Append( CookieKeys.RaffleOrderId, orderId.ToString(), new CookieOptions { Secure = true, SameSite = SameSiteMode.Strict, Expires = new DateTimeOffset(DateTime.Now.AddDays(7)) }); logger.LogInformation($"New Order Created (OrderId: {orderId})"); } order = await mediator.Send(new GetRaffleOrderQuery { OrderId = orderId }); } else { logger.LogInformation("No Order Cookie Found"); var orderId = await mediator.Send(new StartRaffleOrderQuery()); HttpContext.Response.Cookies.Append( CookieKeys.RaffleOrderId, orderId.ToString(), new CookieOptions { Secure = true, SameSite = SameSiteMode.Strict, Expires = new DateTimeOffset(DateTime.Now.AddDays(7)) }); logger.LogInformation($"New Order Created (OrderId: {orderId})"); order = await mediator.Send(new GetRaffleOrderQuery { OrderId = orderId }); } if (HttpContext.Request.Query["emoji"] == "on") { ViewData["emoji"] = "on"; } if (HttpContext.Request.Query["menu"] == "on") { ViewData["graph"] = "on"; } ViewData["itemNumberSortParam"] = sortBy == "itemNumber" ? "itemNumber_desc" : "itemNumber"; ViewData["titleSortParam"] = sortBy == "title" ? "title_desc" : "title"; ViewData["categorySortParam"] = sortBy == "category" ? "category_desc" : "category"; ViewData["pointsSortParam"] = sortBy == "points" ? "points_desc" : "points"; ViewData["currentFilter"] = searchFilter; ViewData["categoryFilter"] = categoryFilter; var raffleItems = raffleItemRepository.GetAll() .Select(x => new RaffleItemModel { Id = x.Id, ItemNumber = x.ItemNumber, Title = x.Title, Description = x.Description, Category = x.Category, Sponsor = x.Sponsor, Cost = x.Cost, Value = x.ItemValue, ForOver21 = x.ForOver21, LocalPickupOnly = x.LocalPickupOnly, IsAvailable = x.IsAvailable, NumberOfDraws = x.NumberOfDraws, TotalTicketsEntered = x.TotalTicketsEntered, Pictures = x.ImageUrls }).ToList(); foreach (var line in order.Lines) { raffleItems.First(x => x.Id == line.RaffleItemId).Amount = line.Count; } if (!string.IsNullOrEmpty(searchFilter)) { raffleItems = raffleItems.Where(x => x.Title.Contains(searchFilter, StringComparison.OrdinalIgnoreCase) || x.Description.Contains(searchFilter, StringComparison.OrdinalIgnoreCase) || x.Category.Contains(searchFilter, StringComparison.OrdinalIgnoreCase)) .ToList(); } if (!string.IsNullOrEmpty(categoryFilter)) { raffleItems = raffleItems.Where(x => x.Category.Equals(categoryFilter, StringComparison.OrdinalIgnoreCase)) .ToList(); } switch (sortBy) { case "title_desc": raffleItems = raffleItems.OrderByDescending(x => x.Title).ToList(); break; case "title": raffleItems = raffleItems.OrderBy(x => x.Title).ToList(); break; case "category": raffleItems = raffleItems.OrderBy(x => x.Category).ToList(); break; case "category_desc": raffleItems = raffleItems.OrderByDescending(x => x.Category).ToList(); break; case "itemNumber": raffleItems = raffleItems.OrderBy(x => x.ItemNumber).ToList(); break; case "itemNumber_desc": raffleItems = raffleItems.OrderByDescending(x => x.ItemNumber).ToList(); break; case "points": raffleItems = raffleItems.OrderBy(x => x.Cost).ToList(); break; case "points_desc": raffleItems = raffleItems.OrderByDescending(x => x.Cost).ToList(); break; default: raffleItems = raffleItems.OrderBy(x => x.ItemNumber).ToList(); break; } var model = new RaffleOrderViewModel { StartDate = raffleEvent.StartDate, CloseDate = raffleEvent.CloseDate.Value.ToUniversalTime(), Categories = raffleItemRepository.GetUsedCategories().OrderBy(x => x).ToList(), RaffleItems = raffleItems }; return(View(model)); }
public async Task <IActionResult> Index(RaffleOrderViewModel model) { RaffleOrder order = null; var raffleEvent = raffleEventRepository.GetById(1); if (DateTime.UtcNow >= raffleEvent.CloseDate) { return(RedirectToAction("Index")); } if (HttpContext.Request.Cookies.ContainsKey(CookieKeys.RaffleOrderId)) { var orderId = int.Parse(HttpContext.Request.Cookies[CookieKeys.RaffleOrderId]); order = (await mediator.Send(new GetRaffleOrderQuery { OrderId = orderId })); } if ((order != null && !order.Lines.Any(x => x.Count > 0)) && !model.RaffleItems.Any(x => x.Amount > 0)) { var raffleItems = raffleItemRepository.GetAll() .Select(x => new RaffleItemModel { Id = x.Id, ItemNumber = x.ItemNumber, Title = x.Title, Description = x.Description, Category = x.Category, Sponsor = x.Sponsor, Cost = x.Cost, Value = x.ItemValue, ForOver21 = x.ForOver21, LocalPickupOnly = x.LocalPickupOnly, NumberOfDraws = x.NumberOfDraws, IsAvailable = x.IsAvailable, TotalTicketsEntered = x.TotalTicketsEntered, Pictures = x.ImageUrls }).ToList(); model = new RaffleOrderViewModel { StartDate = raffleEvent.StartDate, CloseDate = raffleEvent.CloseDate.Value.ToUniversalTime(), Categories = raffleItemRepository.GetUsedCategories().OrderBy(x => x).ToList(), RaffleItems = raffleItems, ErrorMessage = "A raffle needs to be selected." }; return(View(model)); } if (ModelState.IsValid) { if (order != null) { var lineItems = order.Lines.Select(x => new UpdateOrderCommand.RaffleOrderItem { RaffleItemId = x.RaffleItemId, Name = x.Name, Price = x.Price, Count = x.Count }).ToList(); var newLineItems = model.RaffleItems .Where(x => x.Amount > 0) .Select(x => new UpdateOrderCommand.RaffleOrderItem { RaffleItemId = x.Id, Name = $"#{x.ItemNumber} {x.Title}", Price = x.Cost, Count = x.Amount }).ToList(); lineItems.AddRange(newLineItems.Where(x => !lineItems.Any(y => y.RaffleItemId == x.RaffleItemId))); foreach (var item in lineItems) { var newItem = newLineItems.FirstOrDefault(x => x.RaffleItemId == item.RaffleItemId); if (newItem == null) { continue; } item.Price = newItem.Price; item.Count = newItem.Count; } var updateOrder = new UpdateOrderCommand { OrderId = order.Id, ReplaceAll = true, RaffleOrderItems = lineItems }; await mediator.Publish(updateOrder); } else { var startRaffleOrder = new StartRaffleOrderQuery { RaffleOrderItems = model.RaffleItems .Where(x => x.Amount > 0) .Select(x => new StartRaffleOrderQuery.RaffleOrderItem { RaffleItemId = x.Id, Name = $"#{x.ItemNumber} {x.Title}", Price = x.Cost, Count = x.Amount }).ToList() }; var orderId = (await mediator.Send(startRaffleOrder)); order = (await mediator.Send(new GetRaffleOrderQuery { OrderId = orderId })); } HttpContext.Response.Cookies.Append( CookieKeys.RaffleOrderId, order.Id.ToString(), new CookieOptions { Secure = true, SameSite = SameSiteMode.Strict, Expires = new DateTimeOffset(DateTime.Now.AddDays(7)) }); return(RedirectToAction("CompleteRaffle", new { orderId = order.Id })); } return(View(model)); }