public HttpResponseMessage ForgetPassword(ForgetPasswordDTO dto) { try { using (AspodesDB _context = new AspodesDB()) { User user = _context.Users.FirstOrDefault(u => u.IDCard == dto.IDCard && u.Name == dto.Name && u.Person.Status != "D"); if (null == user) { return(ResponseWrapper.ExceptionResponse(new OtherException("填入信息有误"))); } string IdentifyCode = StringExtensions.GetRandomString(6, true, true); Email email = new Email(); email.SenderId = SystemConfig.SenderAddress; email.ReceiverId = user.UserId; email.Content = "[农科院]验证码:" + IdentifyCode + ",农科院用户,您正在通过邮箱重置您的密码[验证码告知他人将导致账号被盗,请勿泄露]"; email.ReciveAddress = user.Person.Email; email.Subject = "农科院"; email.IdentifyCode = IdentifyCode; EmailRepository mailRepository = new EmailRepository(); mailRepository.AddEmail(email); return(ResponseWrapper.SuccessResponse("邮件已发送成果,请注意查收,部分邮件会被自动删除,请在回收箱中仔细查找")); } } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } return(ResponseWrapper.ExceptionResponse(new OtherException("数据库连接错误"))); } catch (Exception e) { var a = e.Message; return(ResponseWrapper.ExceptionResponse(e)); } }
public HttpResponseMessage SendEmail() { try { Email email = new Email(); email.SenderId = SystemConfig.SenderAddress; email.ReceiverId = "*****@*****.**"; email.Content = "邮件测试,看看是否能发送成功aaaaaassssssss"; email.ReciveAddress = "*****@*****.**"; email.Subject = "邮件的主题"; EmailRepository mailRepository = new EmailRepository(); mailRepository.AddEmail(email); return(ResponseWrapper.SuccessResponse("aaaaaaaaaaaaaaaaaaaaa")); } catch (Exception e) { return(ResponseWrapper.ExceptionResponse(e)); } }
public ActionResult Email(Email email) { var userId = User.Identity.GetUserId(); // jeżeli nie przejdzie walidacji if (!ModelState.IsValid) { var vm = PrepareEmailVm(email, userId); return(View("Email", vm)); } if (email.Id == 0) { _emailRepository.AddEmail(email, userId); } else { _emailRepository.UpdateEmail(email, userId); } return(RedirectToAction("Index")); }