Beispiel #1
0
        /// <summary>
        /// Send Customer ComebackMail
        /// </summary>
        /// <param name="v"></param>
        /// <returns></returns>
        private static bool ComeBackEmail(string name)
        {
            try
            {
                //List all customers
                List <Customer> customers = DataLayer.ListCustomers();
                //List all orders
                List <Order>     orders   = DataLayer.ListOrders();
                HashSet <string> sendList = new();

                //loop through list of customers
                foreach (Customer customer in customers)
                {
                    // We send mail if customer hasn't put an order
                    bool Send = true;
                    //loop through list of orders to see if customer don't exist in that list
                    foreach (Order order in orders)
                    {
                        // Email exists in order list
                        if (customer.Email == order.CustomerEmail)
                        {
                            //We don't send email to that customer
                            Send = false;
                        }
                    }

                    //Send if customer hasn't put order
                    if (Send == true)
                    {
                        EmailType2 mailMessage = new(name, customer.Email);
                        SendMails(mailMessage.Message, customer.Email);
                    }
                }
                Console.WriteLine();
                //All mails are sent! Success!
                return(false);
            }
            catch (Exception e)
            {
                //Something went wrong :(
                Console.Error.WriteLine(e.Message);
                return(true);
            }
        }
        /// <summary>
        /// This application is run everyday
        /// </summary>
        /// <param name="args"></param>
        private static void Main(string[] args)
        {
            int  customerListCount    = DataLayer.ListCustomers().Count;                                                  //Sum of all customers
            int  oldCustomerListCount = DataHelper.OldCustomersInList(DataLayer.ListCustomers(), DataLayer.ListOrders()); //Count all the oldCustomers
            int  newCustomerListCount = DataHelper.NewCustomerCount(DataLayer.ListCustomers());
            bool validateCustomerList = DataHelper.CheckListIfNull(DataLayer.ListCustomers());                            //true if list has customer else false

            //Consol information
            Console.WriteLine("Total customers: " + customerListCount);
            Console.WriteLine("Total old customers: " + oldCustomerListCount);
            Console.WriteLine("Total new customers: " + newCustomerListCount);

            //Information to user to see what the applikation is going to do.
            string sendNewCustomerMessage = newCustomerListCount >= 1 ? Constant.NewCustomerMail.sendingWelcomeMail : Constant.NewCustomerMail.notSendingNewCustomerMail;

            //Call the method that sends the mails
            Console.WriteLine(sendNewCustomerMessage);
            bool newCustomerMailSenderValidation = NewCustomerMail.WelcomMail();                              // Start to send mail.

            bool   validateOrderrList     = validateCustomerList == true ? oldCustomerListCount >= 1 : false; //true if list has customer else false
            int    orderListCount         = DataLayer.ListOrders().Count;
            string sendOldCustomerMessage = validateOrderrList == true ? Constant.OldCustomerMail.sendingComeBackMail : Constant.OldCustomerMail.notSenndingComeBackMail;

            Console.WriteLine(sendOldCustomerMessage);

            //Oldcustomer is used to validate so we can keep track on oldCustomerlist and orderList.
            bool oldCustomerMailSenderValidation = validateOrderrList == true ? oldCustomerListCount >= 1 : false;


            oldCustomerMailSenderValidation = DataHelper.DaysOfWeek() ? OldCustomerMail.mailToOldCustomer(OldCustomerMail.GetCustomerList(), OldCustomerMail.GetOrderList()) : false;

            //We send out message on the console to inform about the message that are sent
            string newCustomerMessage = newCustomerMailSenderValidation == true ? Constant.NewCustomerMail.newCustomerMailSent : Constant.NewCustomerMail.newCustomerMailNotSent;
            string oldCustomerMessage = oldCustomerMailSenderValidation == true ? Constant.OldCustomerMail.oldCustomerMailSent: Constant.OldCustomerMail.oldCustomerMailNotsent;

            Console.WriteLine(newCustomerMessage + " \n" + oldCustomerMessage);
            Console.ReadKey();
        }
Beispiel #3
0
        /// <summary>
        /// Send Customer ComebackMail
        /// </summary>
        /// <param name="v"></param>
        /// <returns></returns>
        private static bool DoEmailWork2(string v)
        {
            try
            {
                //List all customers
                List <Customer> e = DataLayer.ListCustomers();
                //List all orders
                List <Order> f = DataLayer.ListOrders();

                //loop through list of customers
                foreach (Customer c in e)
                {
                    // We send mail if customer hasn't put an order
                    bool Send = true;
                    //loop through list of orders to see if customer don't exist in that list
                    foreach (Order o in f)
                    {
                        // Email exists in order list
                        if (c.Email == o.CustomerEmail)
                        {
                            //We don't send email to that customer
                            Send = false;
                        }
                    }

                    //Send if customer hasn't put order
                    if (Send == true)
                    {
                        //Create a new MailMessage
                        System.Net.Mail.MailMessage m = new System.Net.Mail.MailMessage();
                        //Add customer to reciever list
                        m.To.Add(c.Email);
                        //Add subject
                        m.Subject = "We miss you as a customer";
                        //Send mail from [email protected]
                        m.From = new System.Net.Mail.MailAddress("*****@*****.**");
                        //Add body to mail
                        m.Body = "Hi " + c.Email +
                                 "<br>We miss you as a customer. Our shop is filled with nice products. Here is a voucher that gives you 50 kr to shop for." +
                                 "<br>Voucher: " + v +
                                 "<br><br>Best Regards,<br>Our Team";
#if DEBUG
                        //Don't send mails in debug mode, just write the emails in console
                        Console.WriteLine("Send mail to:" + c.Email);
#else
                        //Create a SmtpClient to our smtphost: yoursmtphost
                        System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("yoursmtphost");
                        //Send mail
                        smtp.Send(m);
#endif
                    }
                }
                //All mails are sent! Success!
                return(true);
            }
            catch (Exception)
            {
                //Something went wrong :(
                return(false);
            }
        }