Skip to content

Commit

Permalink
Section 12 - Test Email
Browse files Browse the repository at this point in the history
  • Loading branch information
bhrugen committed Sep 27, 2021
1 parent b51be3d commit 5115291
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion BulkyBook.Utility/EmailSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public Task SendEmailAsync(string email, string subject, string htmlMessage)
using (var emailClient = new SmtpClient())
{
emailClient.Connect("smtp.gmail.com", 587, MailKit.Security.SecureSocketOptions.StartTls);
emailClient.Authenticate("[email protected]", "DotNet213$");
emailClient.Authenticate("[email protected]", "DotNet123$");
emailClient.Send(emailToSend);
emailClient.Disconnect(true);
}
Expand Down
9 changes: 6 additions & 3 deletions BulkyBookWeb/Areas/Customer/Controllers/CartController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using BulkyBook.Models.ViewModels;
using BulkyBook.Utility;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity.UI.Services;
using Microsoft.AspNetCore.Mvc;
using Stripe.Checkout;
using System.Collections.Generic;
Expand All @@ -16,11 +17,13 @@ namespace BulkyBookWeb.Areas.Customer.Controllers
public class CartController : Controller
{
private readonly IUnitOfWork _unitOfWork;
private readonly IEmailSender _emailSender;
[BindProperty]
public ShoppingCartVM ShoppingCartVM { get; set; }
public CartController(IUnitOfWork unitOfWork)
public CartController(IUnitOfWork unitOfWork, IEmailSender emailSender)
{
_unitOfWork = unitOfWork;
_emailSender = emailSender;
}
public IActionResult Index()
{
Expand Down Expand Up @@ -178,7 +181,7 @@ public IActionResult SummaryPOST()

public IActionResult OrderConfirmation(int id)
{
OrderHeader orderHeader = _unitOfWork.OrderHeader.GetFirstOrDefault(u => u.Id == id);
OrderHeader orderHeader = _unitOfWork.OrderHeader.GetFirstOrDefault(u => u.Id == id,includeProperties:"ApplicationUser");
if (orderHeader.PaymentStatus != SD.PaymentStatusDelayedPayment)
{
var service = new SessionService();
Expand All @@ -190,7 +193,7 @@ public IActionResult OrderConfirmation(int id)
_unitOfWork.Save();
}
}

_emailSender.SendEmailAsync(orderHeader.ApplicationUser.Email, "New Order - Bulky Book", "<p>New Order Created</p>");
List<ShoppingCart> shoppingCarts = _unitOfWork.ShoppingCart.GetAll(u => u.ApplicationUserId ==
orderHeader.ApplicationUserId).ToList();
_unitOfWork.ShoppingCart.RemoveRange(shoppingCarts);
Expand Down

0 comments on commit 5115291

Please sign in to comment.