コード例 #1
0
        public async Task <GetLastEmailHistoryCodeInfoByRecipientIdResultDto> GetLastEmailHistoryCodeInfoByRecipientId(string recipientId)
        {
            var emailhistoryInfo = (await _context
                                    .GetByWhere(e => e.RecipientId.Equals(recipientId), true, e => e.CreateTime, SqlSugar.OrderByType.Desc)).First();
            var result = new GetLastEmailHistoryCodeInfoByRecipientIdResultDto();

            // 判断是否为空
            if (emailhistoryInfo == null)
            {
                result.Success    = false;
                result.ResultInfo = string.Format("【{0}】账号暂无邮件历史信息,请检查账号是否正确!如账号准确无误,请联系管理员。", recipientId);
                return(result);
            }
            ModelBindingService.CopyModel(result, emailhistoryInfo);
            // 判断是否过期(10分钟)
            if (emailhistoryInfo.CreateTime.AddMinutes(10) < DateTime.Now)
            {
                return(result = new GetLastEmailHistoryCodeInfoByRecipientIdResultDto
                {
                    RecipientId = recipientId,
                    Success = false,
                    ResultInfo = string.Format("【{0}】账号验证码已过期,请重新发送!", recipientId)
                });
            }
            return(result);
        }
コード例 #2
0
        public async Task <GetLastEmailHistoryInfoByRecipientIdResultDto> GetLastEmailHistoryInfoByRecipientId(string recipientId)
        {
            var emailhistoryInfo = await _context.EmailHistoryInfo
                                   .Where(e => e.IsDeleted == 0)
                                   .OrderByDescending(e => e.CreateTime)
                                   .FirstOrDefaultAsync(e => e.RecipientId.Equals(recipientId));

            var result = new GetLastEmailHistoryInfoByRecipientIdResultDto();

            ModelBindingService.CopyModel(result.EmailHistoryInfo, emailhistoryInfo);
            // 判断是否为空
            if (emailhistoryInfo == null)
            {
                result.Success    = false;
                result.ResultInfo = string.Format("【{0}】账号暂无邮件历史信息,请检查账号是否正确!如账号准确无误,请联系管理员。", recipientId);
                return(result);
            }
            // 判断是否过期(10分钟)
            if (emailhistoryInfo.CreateTime.AddMinutes(10) < DateTime.Now)
            {
                result.Success          = false;
                result.ResultInfo       = string.Format("【{0}】账号验证码已过期,请重新发送!", recipientId);
                result.EmailHistoryInfo = null;
                return(result);
            }
            return(result);
        }
コード例 #3
0
        public async Task <DevLoveInfoDto> GetDevLoveInfoByDLQQ(string dLQQ)
        {
            var devLoveInfo = await _context.DevLoveInfo
                              .Where(d => d.IsDeleted == 0)
                              .FirstOrDefaultAsync(d => d.DLQQ.Equals(dLQQ));

            return(ModelBindingService.CopyModel <DevLoveInfoDto, DevLoveInfo>(devLoveInfo));
        }
コード例 #4
0
        public async Task <ResultDto> UpdateDevLoveInfo(UpdateDevLoveInfoDto updateDevLoveInfoDto)
        {
            // 查询出原有数据
            var devLoveInfo = await _context.DevLoveInfo
                              .FindAsync(updateDevLoveInfoDto.DLId);

            if (devLoveInfo != null)
            {
                // 该QQ账号没有绑定的信息
                throw new Exception("The QQ account has no binding information.");
            }
            ModelBindingService.CopyModel(devLoveInfo, updateDevLoveInfoDto);
            _context.DevLoveInfo.Update(devLoveInfo);
            return(new ResultDto()
            {
                Success = await _context.SaveChangesAsync() > 0 ? true : false
            });
        }
コード例 #5
0
        public async Task <ResultDto> CreateDevLoveInfo(CreateDevLoveInfoDto createDevLoveInfoDto)
        {
            // 判断是否存在该QQ
            var devLoveInfo = await _context.DevLoveInfo
                              .Where(d => d.IsDeleted == 0)
                              .FirstOrDefaultAsync(d => d.DLQQ.Equals(createDevLoveInfoDto.DLQQ));

            if (devLoveInfo != null)
            {
                // 该QQ账号所绑定的信息已存在
                throw new Exception("The information bound to this QQ account already exists.");
            }
            ModelBindingService.CopyModel(devLoveInfo, createDevLoveInfoDto);
            await _context.DevLoveInfo.AddAsync(devLoveInfo);

            return(new ResultDto()
            {
                Success = await _context.SaveChangesAsync() > 0 ? true : false
            });
        }
コード例 #6
0
        public async Task <ResultDto> CreateEmailHistoryInfo(createEmailHistoryInfoDto createEmailHistoryInfoDto)
        {
            // 检测邮箱账号为否为QQ邮箱,并且是否正确
            string expression = AppConfigurtaionService.Configuration["EmailServicesStrings:EmailExpression"]; // 拿到配置文件中的正则表达式

            if (!Regex.IsMatch(createEmailHistoryInfoDto.RecipientId, expression, RegexOptions.Compiled))
            {
                // 请输入正确的QQ邮箱账号
                throw new Exception("Please enter the correct QQ email account.");
            }
            var emailHistory = ModelBindingService.CopyModel <HW_EmailHistoryInfo, createEmailHistoryInfoDto>(createEmailHistoryInfoDto);

            // 发送QQ邮件
            if (createEmailHistoryInfoDto.IsSendEmail)
            {
                emailHistory.EmailBody = _emailServices.SendRandomCodeQQEmail(emailHistory.RecipientId).RecipientBody;
            }
            return(new ResultDto()
            {
                Success = await _context.Add(emailHistory)
            });
        }