Пример #1
0
        private BE.BaseResponse <bool> ProcessSingleBets(List <Tuple <int, decimal, string> > bets, BE.User user)
        {
            Dictionary <BE.UserBet, BE.BaseWalletResponseData> userBets = new Dictionary <BE.UserBet, BE.BaseWalletResponseData>();
            //SportEventsAccess sea = new SportEventsAccess();
            UserBetAccess uba        = new UserBetAccess();
            var           withErrors = false;

            foreach (var bet in bets)
            {
                var sportbet = sea.GetSportBet(bet.Item1);
                var userbet  = new BE.UserBet();
                userbet.UserID        = user.ID;
                userbet.SportBetID    = sportbet.ID;
                userbet.MatchCode     = sportbet.SportEvent.Code;
                userbet.MatchName     = sportbet.SportEvent.Name;
                userbet.PaymentStatus = null;
                userbet.Hit           = null;
                userbet.TransactionID = Guid.NewGuid().ToString();
                userbet.LinkedCode    = null;
                var oddProvider = userbet.GetOddProvider(sportbet.Code);
                userbet.BetType  = bet.Item3;
                userbet.Amount   = bet.Item2;
                userbet.BetPrice = oddProvider.GetOddValue(bet.Item3, sportbet);

                string detail = GetDebitDetail(userbet, user);

                BE.DebitRequest req = new BE.DebitRequest();
                req.Amount        = userbet.Amount;
                req.BetDetail     = detail;
                req.EventID       = userbet.MatchCode;
                req.EventName     = userbet.MatchName;
                req.SessionToken  = user.SessionToken;
                req.UserUID       = user.UID;
                req.TransactionID = userbet.TransactionID;

                var betValidated = BetValidatorExtension.ValidateBet(sportbet.SportEvent.Sport.Code, userbet.Amount, userbet.BetPrice, user.Balance);
                if (betValidated.Status.Equals(ResponseStatus.OK) && betValidated.GetData())
                {
                    BE.BaseResponse <BE.BaseWalletResponseData> response = UserWalletFacade.ProcessBetDebit(req);
                    userBets.Add(userbet, response.GetData());
                    if (response.Status.Equals(BE.ResponseStatus.Fail))
                    {
                        RequestContextHelper.LastError = response.Message;
                        withErrors = true;
                        break;
                    }

                    RequestContextHelper.SessionToken = response.GetData().SessionToken;
                    RequestContextHelper.UserBalance  = response.GetData().Balance;
                    RequestContextHelper.UserName     = response.GetData().NickName;

                    user.SessionToken = response.GetData().SessionToken;
                    user.Balance      = response.GetData().Balance;
                }
                else
                {
                    return(new BaseResponse <bool>(false, ResponseStatus.Fail, betValidated.Message));
                }
            }

            if (withErrors)
            {
                new Thread(delegate()
                {
                    DoRollBack(userBets);
                }).Start();
            }
            else
            {
                if (!uba.StoreUserBet(userBets.Keys.ToList()))
                {
                    new Thread(delegate()
                    {
                        DoRollBack(userBets);
                    }).Start();
                    return(new BE.BaseResponse <bool>(false, BE.ResponseStatus.Fail, "No se pudo guardar la apuesta por un error interno"));
                }
            }

            UserAccess ua = new UserAccess();

            user = ua.UpdateUser(user);

            return(new BE.BaseResponse <bool>(true, BE.ResponseStatus.OK));
        }
Пример #2
0
        private BE.BaseResponse <bool> ProcessCombinedBets(decimal betAmount, List <Tuple <int, decimal, string> > bets, BE.User user)
        {
            List <BE.UserBet> userBets = new List <BE.UserBet>();
            //SportEventsAccess sea = new SportEventsAccess();
            string        transaction   = Guid.NewGuid().ToString();
            decimal       totalBetPrice = 1M;
            List <string> sportCodes    = new List <string>();

            foreach (var bet in bets)
            {
                var sportbet = sea.GetSportBet(bet.Item1);
                var userbet  = new BE.UserBet();
                userbet.UserID        = user.ID;
                userbet.SportBetID    = sportbet.ID;
                userbet.MatchCode     = sportbet.SportEvent.Code;
                userbet.MatchName     = sportbet.SportEvent.Name;
                userbet.PaymentStatus = null;
                userbet.Hit           = null;
                userbet.TransactionID = transaction;
                userbet.LinkedCode    = transaction;
                var oddProvider = userbet.GetOddProvider(sportbet.Code);
                userbet.BetType = bet.Item3;
                userbet.Amount  = userBets.Count > 0 ? 0M : betAmount;

                totalBetPrice *= oddProvider.GetOddValue(bet.Item3, sportbet);

                userBets.Add(userbet);

                sportCodes.Add(sportbet.SportEvent.Sport.Code);
            }

            userBets.ForEach(p => p.BetPrice = totalBetPrice);

            string detail = GetDebitDetail(userBets, user);

            BE.DebitRequest req = new BE.DebitRequest();
            req.Amount        = userBets[0].Amount;
            req.BetDetail     = detail;
            req.EventID       = string.Join(",", userBets.Select(p => p.MatchCode).ToArray());
            req.EventName     = string.Join(",", userBets.Select(p => p.MatchName).ToArray());
            req.SessionToken  = user.SessionToken;
            req.UserUID       = user.UID;
            req.TransactionID = userBets[0].TransactionID;

            Dictionary <BE.UserBet, BE.BaseWalletResponseData> combinedBet = new Dictionary <BE.UserBet, BE.BaseWalletResponseData>();

            var validatedBet = BetValidatorExtension.ValidateBet(sportCodes.ToArray(), totalBetPrice, betAmount, user.Balance);

            if (validatedBet.Status.Equals(ResponseStatus.OK) && validatedBet.GetData())
            {
                BE.BaseResponse <BE.BaseWalletResponseData> response = UserWalletFacade.ProcessBetDebit(req);
                if (response.Status.Equals(BE.ResponseStatus.Fail))
                {
                    RequestContextHelper.LastError = response.Message;

                    userBets.ForEach(ub => combinedBet.Add(ub, response.GetData()));
                    new Thread(delegate()
                    {
                        DoRollBack(combinedBet);
                    }).Start();
                    return(new BE.BaseResponse <bool>(false, BE.ResponseStatus.Fail, response.Message));
                }
                UserBetAccess uba = new UserBetAccess();
                if (!uba.StoreUserBet(userBets))
                {
                    new Thread(delegate()
                    {
                        DoRollBack(combinedBet);
                    }).Start();
                    return(new BE.BaseResponse <bool>(false, BE.ResponseStatus.Fail, "No se pudo guardar la puesta por un error interno"));
                }

                RequestContextHelper.SessionToken = response.GetData().SessionToken;
                RequestContextHelper.UserBalance  = response.GetData().Balance;
                RequestContextHelper.UserName     = response.GetData().NickName;


                user.SessionToken = response.GetData().SessionToken;
                user.Balance      = response.GetData().Balance;

                UserAccess ua = new UserAccess();
                user = ua.UpdateUser(user);

                return(new BE.BaseResponse <bool>(true, BE.ResponseStatus.OK));
            }
            else
            {
                return(new BaseResponse <bool>(false, ResponseStatus.Fail, validatedBet.Message));
            }
        }