示例#1
0
        public void ProcessOrder(RegisterDetail registerDetail)
        {
            SmtpClient smtp = new SmtpClient();

            using (var smtpClient = new SmtpClient())
            {
                smtpClient.EnableSsl             = emailSettings.UseSsl;
                smtpClient.Host                  = emailSettings.ServerName;
                smtpClient.Port                  = emailSettings.ServerPort;
                smtpClient.UseDefaultCredentials = true;
                smtpClient.Credentials           = new NetworkCredential(emailSettings.Username, emailSettings.Password);
                smtpClient.DeliveryMethod        = SmtpDeliveryMethod.Network;

                StringBuilder body = new StringBuilder();

                body.AppendLine("---")
                .AppendLine("用户注册信息:")
                .AppendLine(string.Format("账户名:{0}  密码:{1}", registerDetail.Name, registerDetail.Password));

                MailMessage mailMessage = new MailMessage(
                    emailSettings.MailFromAddress,
                    emailSettings.MailToAddress,
                    string.Format("注册日期:{0}", System.DateTime.Now.ToString()),
                    body.ToString());
                mailMessage.BodyEncoding = Encoding.UTF8;
                smtpClient.Send(mailMessage);
            }
        }
示例#2
0
 //用户注册
 public void Register(RegisterDetail register)
 {
     //db是一个具有各项模型属性的上下文类
     using (var db = new 校园自助图书管理系统Entities())
     {
         //创建事务
         using (var dbContextTransaction = db.Database.BeginTransaction())
         {
             try
             {
                 //int maxID = db.Reader.Max(r => r.Id);
                 Reader re = new Reader();
                 re.Name     = register.Name;
                 re.Password = register.Password;
                 re.Price    = 0;
                 re.ClassId  = 1;
                 re.Email    = register.Email;
                 //re.Id = maxID + 1;
                 db.Reader.Add(re);
                 db.SaveChanges();
                 dbContextTransaction.Commit();
             }
             catch (Exception)
             {
                 dbContextTransaction.Rollback();
             }
         }
     }
 }