Advertisement
giaynhap123

eventchange

Apr 19th, 2018
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.13 KB | None | 0 0
  1.      public ActionResult sendMail()
  2.         {
  3.             string mail = (Request["mail"]);
  4.             string body = Request["body"];
  5.             if (mail == null) return null;
  6.             USER_UD user = null;
  7.             user = USER_UDRepo.GetByUsername(mail);
  8.             ResultData result = new ResultData();
  9.  
  10.             if (user == null) { result.ERR_CODE = 1;
  11.                 result.Message = "Không tìm thấy tài khoản người dùng trong cơ sở dữ liệu.";
  12.                 goto Done;
  13.                  
  14.             }
  15.             else result.ERR_CODE = 0;
  16.             result.DATA = user;
  17.  
  18.  
  19.             var fromAddress = new MailAddress("kmavnteam@gmail.com", "Bệnh Viện Phụ Sản Hà Nội");
  20.             var toAddress = new MailAddress(mail, "");
  21.          
  22.             const string subject = "Bệnh Viện Phụ Sản Hà Nội";
  23.             var smtp = new SmtpClient
  24.             {
  25.                 Host = "smtp.gmail.com",
  26.                 Port = 587,
  27.                 EnableSsl = true,
  28.                 DeliveryMethod = SmtpDeliveryMethod.Network,
  29.                 UseDefaultCredentials = false,
  30.                 Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
  31.             };
  32.             using (var message = new MailMessage(fromAddress, toAddress)
  33.             {
  34.                 Subject = subject,
  35.                 Body = body
  36.             })
  37.             {
  38.                 smtp.Send(message);
  39.             }      
  40.            Done:    
  41.             return Json(result, JsonRequestBehavior.AllowGet);
  42.         }
  43.         public ActionResult changePass()
  44.         {
  45.             int u_id = int.Parse(Request["id"]);
  46.             ResultData result = new ResultData();
  47.             result.ERR_CODE = 1;
  48.             USER_UD userUd = USER_UDRepo.GetByID(u_id);
  49.             if (userUd != null) {
  50.                 userUd.password = Request["pass"].Password();
  51.                 USER_UDRepo.Save(userUd);
  52.                 result.ERR_CODE = 0;
  53.             }        
  54.             result.Message = "Cập nhật thông tin thành công";
  55.             return Json(result, JsonRequestBehavior.AllowGet);
  56.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement