Example #1
0
        private async Task <bool> WinnerScoringAsync(AppDbContext ltctx, int scoring_no)
        {
            var _result = false;

            try
            {
                ltctx.Database.BeginTransaction();

                // 채점 하고자는 차수의 당첨번호
                var _winner = ltctx.tb_lion_winner
                              .Where(w => w.SequenceNo == scoring_no)
                              .SingleOrDefault();

                if (_winner != null)
                {
                    var _wdigits = new List <short>();
                    {
                        _wdigits.Add(_winner.Digit1);
                        _wdigits.Add(_winner.Digit2);
                        _wdigits.Add(_winner.Digit3);
                        _wdigits.Add(_winner.Digit4);
                        _wdigits.Add(_winner.Digit5);
                        _wdigits.Add(_winner.Digit6);
                    }

                    var _no_select = ltctx.tb_lion_select
                                     .Where(x => x.SequenceNo == scoring_no && x.Ranking == 0)
                                     .Count();

                    // 채점 할 내용이 없으면 skip
                    if (_no_select > 0)
                    {
                        var _factor = _winnerSelector.GetFactor(ltctx, scoring_no);

                        // 회차 별 전체 select(추출) 내용 채점 실시
                        // 낙첨(6위) select(추출) 번호는 삭제 함
                        _winnerScoring.SelectScoring(ltctx, _winner, _factor, _wdigits);
                    }

                    var _choice_ids = ltctx.tb_lion_choice
                                      .Where(c => c.SequenceNo == scoring_no && c.Ranking == 0)
                                      .GroupBy(c => c.LoginId)
                                      .Select(c => c.Key)
                                      .ToList();

                    // member(회원) 별 choice(선택) 내용 채점 실시
                    foreach (var _login_id in _choice_ids)
                    {
                        var _member = ltctx.tb_lion_member
                                      .Where(m => m.LoginId == _login_id)
                                      .SingleOrDefault();
                        if (_member == null)
                        {
                            continue;
                        }

                        var _no_choice = ltctx.tb_lion_choice
                                         .Where(x => x.SequenceNo == scoring_no && x.LoginId == _login_id && x.Ranking == 0)
                                         .Count();

                        if (_no_choice <= 0)
                        {
                            continue;
                        }

                        var _jackpot = _winnerScoring.GetJackpot(ltctx, _member, scoring_no, (short)_no_choice);
                        _winnerScoring.ChoiceScoring(ltctx, _winner, _jackpot, _wdigits, _login_id);
                    }

                    await ltctx.SaveChangesAsync();
                }

                ltctx.Database.CommitTransaction();
                _result = true;
            }
            catch (Exception ex)
            {
                ltctx.Database.RollbackTransaction();

                _logger.LogError(ex, "receiver.analyst");
            }

            return(_result);
        }
Example #2
0
        private async Task <int> NextGameSenderAsync(AppDbContext ltctx, mWinner winner, mMember member, dChoice choice)
        {
            var _result = 0;

            try
            {
                ltctx.Database.BeginTransaction();

                if (member.MailError == false)
                {
                    var _choices = ltctx.tb_lion_choice
                                   .Where(c => c.SequenceNo == choice.sequence_no && c.LoginId == choice.login_id &&
                                          (c.IsMailSent == false || choice.resend == true))
                                   .OrderBy(c => c.Digit1).ThenBy(c => c.Digit2).ThenBy(c => c.Digit3)
                                   .ThenBy(c => c.Digit4).ThenBy(c => c.Digit5).ThenBy(c => c.Digit6)
                                   .ToArray();

                    choice.no_choice = _choices.Length;

                    // 해당 회차에 처리하고자 하는 회원에게 메일 발송이 안된 entity만을 처리 합니다.
                    if (choice.no_choice > 0)
                    {
                        var _verify = await _mailSender.TestMailServerConnectionAsync(member);

                        if (_verify.error_code == SmtpError.GENERIC_SUCCESS)
                        {
                            var _curr_factor = _winnerSelector.GetFactor(ltctx, choice.sequence_no - 0);
                            var _last_factor = _winnerSelector.GetFactor(ltctx, choice.sequence_no - 1);

                            // 선택 번호들을 이미지 처리 함, 최종 zip(압축) 파일로 생성 합니다.
                            var _zip_file = _printOut.SaveLottoSheet(_choices, choice);

                            var _last_jackpot = _winnerScoring.GetJackpot(ltctx, member, choice.sequence_no - 1, member.MaxSelectNumber);

                            // zip 파일을 첨부 하여 메일 발송 합니다.
                            await _mailSender.SendLottoZipFile(_zip_file, choice, winner, member, _curr_factor, _last_factor, _last_jackpot);

                            // 메일 발송 했음을 표기 함
                            _choices
                            .ToList()
                            .ForEach(c => c.IsMailSent = true);

                            _result = choice.no_choice;
                        }
                        else
                        {
                            WriteMember(choice.sequence_no, choice.login_id, $"mail error '{member.EmailAddress}', {_verify.error_code}, {_verify.error_message}");
                        }

                        await ltctx.SaveChangesAsync();
                    }
                }

                ltctx.Database.CommitTransaction();
            }
            catch (Exception ex)
            {
                ltctx.Database.RollbackTransaction();

                _logger.LogError(ex, "receiver.choicer");
            }

            return(_result);
        }