public void AddExpert(Expert expert)
 {
     var insertExpert = new SqlCommand(@"INSERT INTO [dbo].[Ks_Expert] ([ZID], [Course], [First_Name], [Last_Name], [Email])
                                            VALUES (@zid, @course, @firstMan, @lastName, @email)", _connection);
     insertExpert.Parameters.AddWithValue("@zid", expert.Zid == null ? DBNull.Value.ToString() : expert.Zid);
     insertExpert.Parameters.AddWithValue("@firstMan", expert.FirstName == null ? DBNull.Value.ToString() : expert.FirstName);
     insertExpert.Parameters.AddWithValue("@lastName", expert.LastName == null ? DBNull.Value.ToString() : expert.LastName);
     insertExpert.Parameters.AddWithValue("@email", expert.Email == null ? DBNull.Value.ToString() : expert.Email);
     insertExpert.Parameters.AddWithValue("@course", expert.Course == null ? DBNull.Value.ToString() : expert.Course);
     _connection.Open();
     insertExpert.ExecuteNonQuery();
     _connection.Close();
 }
        private static void SendEmail(Expert expert)
        {
            var from = new MailAddress("*****@*****.**", "KnowledgeShare");
            var to = new MailAddress(expert.Email);
            var mail = new MailMessage(from, to)
            {
                Subject = "Enrolled as an Expert",
                Body = "You have been successfully enrolled as an expert for course" + " " + expert.Course
            };

            var ms = new SmtpClient("smtpcorp.com")
            {
                Credentials = new NetworkCredential("*****@*****.**", "lucky_123"),
                Port = 2525
            };
            ms.Send(mail);
        }
        public string AddExpert(Expert expert)
        {
            var checkExpert = _expertRepository.GetCourses(expert.Zid);
            if (checkExpert.Any(course => course.Course == expert.Course))
            {
                return "You already enrolled for this course";
            }

            _expertRepository.AddExpert(expert);

            try
            {
                SendEmail(expert);
            }
            catch (Exception ex)
            {

                Console.WriteLine(ex);
            }

            return "Successfully Enrolled As Expert";
        }