Exemplo n.º 1
0
        public int SendRecoveryPasswordEMail(ForgetPasswordViewModel fpvm)
        {
            using (AssignmentManagementSystemEntities db = new AssignmentManagementSystemEntities())
            {
                tblStudent tb  = db.tblStudents.Where(s => s.Email == fpvm.Email).FirstOrDefault();
                tblTeacher tb1 = db.tblTeachers.Where(t => t.Email == fpvm.Email).FirstOrDefault();
                tblAdmin   tb2 = db.tblAdmins.Where(a => a.Email == fpvm.Email).FirstOrDefault();
                try
                {
                    string password = "";
                    if (tb != null)
                    {
                        password = tb.Password;
                    }
                    else if (tb1 != null)
                    {
                        password = tb1.Password;
                    }
                    else
                    {
                        password = tb2.Password;
                    }

                    if (tb != null || tb1 != null || tb2 != null)
                    {
                        var          fromAddress  = new MailAddress("*****@*****.**", "santoshmandal97788");
                        var          toAddress    = new MailAddress(fpvm.Email, "To Name");
                        const string fromPassword = "******";
                        const string subject      = "Assignment Management System Password Recovery:";

                        var sendpwd = password;
                        var smtp    = new SmtpClient
                        {
                            Host                  = "smtp.gmail.com",
                            Port                  = 587,
                            EnableSsl             = true,
                            DeliveryMethod        = SmtpDeliveryMethod.Network,
                            UseDefaultCredentials = false,
                            Credentials           = new NetworkCredential(fromAddress.Address, fromPassword)
                        };
                        using (var message = new MailMessage(fromAddress, toAddress)
                        {
                            Subject = subject,
                            Body = "Hi!" + "Your Assignment Management System Password is: " + sendpwd
                        })
                        {
                            smtp.Send(message);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                }
                return(0);
            }
        }
        public string SendEMail(int sectionid, int semesterid, int facultyid, AssignmentRoutineViewModel arvm)
        {
            using (AssignmentManagementSystemEntities db = new AssignmentManagementSystemEntities())
            {
                List <tblStudent> tb = db.tblStudents.Where(x => x.Section_Id == sectionid && x.Semester_Id == semesterid && x.Faculty_Id == facultyid).ToList();
                //var tb1 = db.tblStudents.ToList();



                try
                {
                    foreach (var item in tb)
                    {
                        if (tb != null)
                        {
                            var          fromAddress  = new MailAddress("*****@*****.**", "santoshmandal97788");
                            var          toAddress    = new MailAddress(item.Email, "To Name");
                            const string fromPassword = "******";
                            const string subject      = "Assignment Management System";
                            var          studentname  = item.Name;


                            var smtp = new SmtpClient
                            {
                                Host                  = "smtp.gmail.com",
                                Port                  = 587,
                                EnableSsl             = true,
                                DeliveryMethod        = SmtpDeliveryMethod.Network,
                                UseDefaultCredentials = false,
                                Credentials           = new NetworkCredential(fromAddress.Address, fromPassword)
                            };
                            using (var message = new MailMessage(fromAddress, toAddress)
                            {
                                Subject = subject,
                                Body = "Hi!" + " " + studentname + " " + "Your " + arvm.Assignment_Name + " Assignment is Released and Deadline is " + arvm.Deadline
                            })
                            {
                                smtp.Send(message);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                }
                return("Email Sent");
            }
        }
        public int SendEMail(int id)
        {
            using (AssignmentManagementSystemEntities db = new AssignmentManagementSystemEntities())
            {
                tblStudent tb = db.tblStudents.Where(x => x.Student_Id == id).FirstOrDefault();


                try
                {
                    if (tb != null)
                    {
                        var          fromAddress  = new MailAddress("*****@*****.**", "santoshmandal97788");
                        var          toAddress    = new MailAddress(tb.Email, "To Name");
                        const string fromPassword = "******";
                        const string subject      = "Assignment Management System";
                        var          studentname  = tb.Name;
                        var          Email        = tb.Email;
                        var          Password     = tb.Password;
                        var          smtp         = new SmtpClient
                        {
                            Host                  = "smtp.gmail.com",
                            Port                  = 587,
                            EnableSsl             = true,
                            DeliveryMethod        = SmtpDeliveryMethod.Network,
                            UseDefaultCredentials = false,
                            Credentials           = new NetworkCredential(fromAddress.Address, fromPassword)
                        };
                        using (var message = new MailMessage(fromAddress, toAddress)
                        {
                            Subject = subject,
                            Body = "Hi!" + " " + studentname + " " + "Your Assignment Management System Account is Created. And Your Login Credential is Email: " + Email + " " + "and Password: " + Password
                        })
                        {
                            smtp.Send(message);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                }
                return(id);
            }
        }