예제 #1
0
        static void SendMail()
        {
            Console.WriteLine("Для кого сообщение?");
            using (var reciversRepository = new ReciversRepository())
                using (var mailsRepository = new MailsRepository())
                {
                    Mail mail      = new Mail();
                    int  ineration = 1;
                    var  recivers  = reciversRepository.GetAll();

                    foreach (var reciver in recivers)
                    {
                        Console.WriteLine($"{ineration}: {reciver.FullName}");
                    }

                    int reciverNumber;

                    if (int.TryParse(Console.ReadLine(), out reciverNumber) && recivers.Count >= reciverNumber)
                    {
                        mail.Reciver   = recivers.ElementAt(reciverNumber - 1);
                        mail.ReciverId = recivers.ElementAt(reciverNumber - 1).Id;
                    }
                    else
                    {
                        return;
                    }

                    Console.WriteLine("Тема сообщения: ");
                    mail.Theme = Console.ReadLine();
                    Console.WriteLine("Введите сообщение: ");
                    mail.Text = Console.ReadLine();

                    mailsRepository.Add(mail);
                }
        }
예제 #2
0
        static void SendEmail()
        {
            Console.WriteLine("Кому отправить сообщение?");

            using (var receiversRepository = new ReceiverRepository())
                using (var mailsRepository = new MailsRepository())
                {
                    Mail mail      = new Mail();
                    int  ineration = 1;
                    var  receivers = receiversRepository.GetAll();

                    foreach (var receiver in receivers)
                    {
                        Console.WriteLine(ineration + ": " + receiver.FullName);
                    }

                    int receiverNumber;

                    if (int.TryParse(Console.ReadLine(), out receiverNumber) && receivers.Count >= receiverNumber)
                    {
                        mail.Receiver   = receivers.ElementAt(receiverNumber - 1);
                        mail.ReceiverId = receivers.ElementAt(receiverNumber - 1).Id;
                    }
                    else
                    {
                        return;
                    }

                    Console.WriteLine("Введите тему сообщения");
                    mail.Theme = Console.ReadLine();

                    Console.WriteLine("Введите сообщениe");
                    mail.Text = Console.ReadLine();

                    mailsRepository.Add(mail);
                }
        }