Ejemplo 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);
            }
        }
Ejemplo n.º 2
0
 public int Add(TeacherViewModel tvm)
 {
     try
     {
         tblTeacher tb = new tblTeacher();
         tb.Name     = tvm.Name;
         tb.Email    = tvm.Email;
         tb.Password = CreateRandomPassword(5);
         tb.Phone    = tvm.Phone;
         tb.Address  = tvm.Address;
         _db.tblTeachers.Add(tb);
         _db.SaveChanges();
         tblMainLog tml       = new tblMainLog();
         var        principal = System.Security.Claims.ClaimsPrincipal.Current;
         string     Name      = principal.FindFirst(ClaimsIdentity.DefaultNameClaimType).Value;
         str             = "New Teacher Added With Name- '" + tvm.Name + "' " + ", Email- '" + tvm.Email + "' " + ", Phone- '" + tvm.Phone + "' " + "and Address- '" + tvm.Address + "Added by Admin";
         tml.Description = str;
         tml.AdminName   = Name;
         tml.Date        = System.DateTime.Now;
         tml.EntityId    = 4;
         tml.ItemId      = tb.Teacher_Id;
         _db.tblMainLogs.Add(tml);
         return(_db.SaveChanges());
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 3
0
 public int Delete(int ID)
 {
     try
     {
         tblTeacher tb = _db.tblTeachers.Where(t => t.Teacher_Id == ID).FirstOrDefault();
         _db.tblTeachers.Remove(tb);
         return(_db.SaveChanges());
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public int ChangePassword(int?teacherid, ChangePasswordViewModel cvm)
 {
     try
     {
         tblTeacher tb = _db.tblTeachers.Where(s => s.Teacher_Id == teacherid && s.Password == cvm.OldPassword).FirstOrDefault();
         if (tb != null)
         {
             tb.Password = cvm.ConfirmNewPassword;
         }
         return(_db.SaveChanges());
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 5
0
        public int SendEmail(int id)
        {
            using (AssignmentManagementSystemEntities db = new AssignmentManagementSystemEntities())
            {
                tblTeacher tb = db.tblTeachers.Where(x => x.Teacher_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      = " ISMT COLLEGE Assignment Management System";
                        var          teachername  = 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!" + " " + teachername + " " + "Your Assignment Management System  For Teacher Account is Created. And Your Login Credential is Email: " + Email + " " + "and Password: " + Password
                        })
                        {
                            smtp.Send(message);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                }
                return(id);
            }
        }
Ejemplo n.º 6
0
        public int Update(TeacherViewModel tvm)
        {
            try
            {
                tblTeacher tb = _db.tblTeachers.Where(t => t.Teacher_Id == tvm.Id).FirstOrDefault();

                //var oldName = tb.Name;
                //var oldEmail = tb.Email;
                //var oldPhone = tb.Phone;
                //var oldAddress = tb.Address;
                List <string> lstchange = new List <string>();
                if (tb.Name != tvm.Name)
                {
                    lstchange.Add("name from " + tb.Name + " to " + tvm.Name);
                }
                if (tb.Email != tvm.Email)
                {
                    lstchange.Add("email from " + tb.Email + " to " + tvm.Email);
                }
                if (tb.Phone != tvm.Phone)
                {
                    lstchange.Add("phone from " + tb.Phone + " to " + tvm.Phone);
                }
                if (tb.Address != tvm.Address)
                {
                    lstchange.Add("address from " + tb.Address + " to " + tvm.Address);
                }
                tb.Name     = tvm.Name;
                tb.Email    = tvm.Email;
                tb.Password = tb.Password;
                tb.Phone    = tvm.Phone;
                tb.Address  = tvm.Address;
                //_db.SaveChanges();
                if (lstchange.Count == 0)
                {
                    return(_db.SaveChanges());
                }
                else
                {
                    tblMainLog tml       = new tblMainLog();
                    var        principal = System.Security.Claims.ClaimsPrincipal.Current;
                    string     Name      = principal.FindFirst(ClaimsIdentity.DefaultNameClaimType).Value;
                    foreach (var item in lstchange)
                    {
                        str += item + ",";
                    }
                    string str2 = str;
                    tml.Description = str;
                    tml.AdminName   = Name;
                    tml.Date        = System.DateTime.Now;
                    tml.EntityId    = 4;
                    tml.ItemId      = tb.Teacher_Id;
                    _db.tblMainLogs.Add(tml);
                    return(_db.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }