Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update EmailSender.cs #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Codecool.CodecoolShop/Email/EmailSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

internal static class Email
{
public static void SendEmail(Order order, List<OrderedProduct> products)
public static void SendEmail(Order order, List<OrderedProduct> products) //Lista pozwala na modyfikacje kolekcji, nie chcemy jej modyfikowac dlatego nie powinno sie przekazywac tego jako lista, jak juz to arrayem
{
var emailTo = order.Address.Email;
var client = new SmtpClient("smtp.gmail.com", 587)
Expand All @@ -16,15 +16,15 @@ public static void SendEmail(Order order, List<OrderedProduct> products)
};
var message = CreateMessage(order, products);
client.Send("[email protected]", emailTo,
$"CodeCool Shop - You buy {products.Sum(p => p.Quantity)} products", message);
$"CodeCool Shop - You buy {products.Sum(p => p.Quantity)} products", message); //jezeli products bedzie pusty to Sum wywali Ci bledem
}

private static string CreateMessage(Order order, List<OrderedProduct> products)
{
var message = $"Hello {order.Address.FullName},\nHere is you confirmation order.\nYou buy:\n\n";
foreach (var product in products)
message +=
$"Name: {product.Name}\nPrice: {product.Price}\nQuantity: {product.Quantity}\n\n";
$"Name: {product.Name}\nPrice: {product.Price}\nQuantity: {product.Quantity}\n\n"; //daj jakies klamerki bo to strasznie wyglada ciezko sie czyta czy ten kod nadal jest w foreachu czy nie

message +=
$"Total price: {products.Sum(p => p.Quantity * p.Price)}\nTotal products: {products.Sum(p => p.Quantity)}\n\n";
Expand All @@ -33,4 +33,4 @@ private static string CreateMessage(Order order, List<OrderedProduct> products)
$"Country: {order.Address.Country}\nEmail: {order.Address.Email}\nPhone: {order.Address.Phone}\n";
return message;
}
}
}