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);
        }