コード例 #1
0
        private string GetDebitDetail(List <BE.UserBet> userbets, BE.User user)
        {
            XElement detail = new XElement("BetDetail",
                                           new XElement("BetType", "combined"),
                                           new XElement("UserUID", user.UID),
                                           new XElement("TransactionID", userbets[0].TransactionID),
                                           new XElement("BetAmount", userbets[0].Amount),
                                           new XElement("BetPrice", userbets[0].BetPrice),
                                           new XElement("Date", DateTime.UtcNow));

            XElement eventsDetail = new XElement("EventsDetails");

            foreach (var userbet in userbets)
            {
                XElement matchDetails = new XElement("MatchDetail",
                                                     new XElement("MatchCode", userbet.MatchCode),
                                                     new XElement("MatchName", userbet.MatchName),
                                                     new XElement("BetName", userbet.BetType)
                                                     );

                eventsDetail.Add(matchDetails);
            }

            detail.Add(eventsDetail);
            return(detail.ToString(SaveOptions.DisableFormatting));
        }
コード例 #2
0
        public BE.User UpdateUser(BE.User userData)
        {
            using (var db = new BE.ADOLDBEntities())
            {
                var user = db.Users.Where(p => p.UID.Equals(userData.UID)).First();
                user.LaunchToken  = userData.LaunchToken;
                user.SessionToken = userData.SessionToken;
                user.Balance      = userData.Balance;
                db.Users.Attach(user);
                db.Entry(user).State = System.Data.EntityState.Modified;

                db.SaveChanges();
            }
            return(userData);
        }
コード例 #3
0
        private string GetDebitDetail(BE.UserBet userbet, BE.User user)
        {
            XElement detail = new XElement("BetDetail",
                                           new XElement("BetType", "single"),
                                           new XElement("UserUID", user.UID),
                                           new XElement("TransactionID", userbet.TransactionID),
                                           new XElement("MatchCode", userbet.MatchCode),
                                           new XElement("MatchName", userbet.MatchName),
                                           new XElement("BetName", userbet.BetType),
                                           new XElement("BetPrice", userbet.BetPrice),
                                           new XElement("BetAmount", userbet.Amount),
                                           new XElement("Date", DateTime.UtcNow)
                                           );

            return(detail.ToString(SaveOptions.DisableFormatting));
        }
コード例 #4
0
        public List <SportDTO> GetActiveSports(BE.BaseRequest req)
        {
            SportEventsAccess seax = new SportEventsAccess();
            var successLogin       = true;

            if (!string.IsNullOrEmpty(req.LaunchToken) && string.IsNullOrEmpty(RequestContextHelper.SessionToken))
            {
                var response = UserWalletFacade.ProcessLogin(req);
                if (response.Status.Equals(BE.ResponseStatus.OK))
                {
                    //RequestContextHelper.SessionToken = response.GetData().SessionToken;
                    //RequestContextHelper.UserBalance = response.GetData().Balance;
                    //RequestContextHelper.UserName = response.GetData().NickName;

                    UserAccess ua   = new UserAccess();
                    BE.User    user = new BE.User();
                    user.LaunchToken  = req.LaunchToken;
                    user.SessionToken = response.GetData().SessionToken;
                    user.UID          = response.GetData().UserUID;
                    user.Balance      = response.GetData().Balance;
                    user.NickName     = response.GetData().NickName;

                    ua.LoginUser(user);
                    this.UpdateCurrentUserData(user);
                }
                else
                {
                    successLogin = false;
                    RequestContextHelper.LastError = response.Message;
                }
            }

            if (successLogin)
            {
                List <BE.Sport> sports = seax.GetActiveSports();

                List <SportDTO> sportsDto = new List <SportDTO>();

                string lastCode = null, lastRegion = null, lastCountry = null;

                foreach (var sport in sports.OrderBy(s => s.Code).ThenBy(s => s.RegionName).ThenBy(s => s.CountryName).ThenBy(s => s.Name))
                {
                    if (lastCode != sport.Code)
                    {
                        lastCode = sport.Code;
                        SportDTO         viewSport = new SportDTO();
                        List <RegionDTO> regions   = new List <RegionDTO>();

                        viewSport.Code = lastCode;
                        viewSport.Name = sport.Name;

                        foreach (var region in sports.Where(s => s.Code == lastCode).OrderBy(s => s.RegionName).ThenBy(s => s.CountryName).ThenBy(s => s.Name))
                        {
                            if (lastRegion != region.RegionID)
                            {
                                lastRegion = region.RegionID;
                                RegionDTO         newRegion = new RegionDTO();
                                List <CountryDTO> countries = new List <CountryDTO>();

                                newRegion.Name = region.RegionName;
                                newRegion.Code = region.RegionID;

                                #region paises
                                foreach (var pais in sports.Where(s => s.Code == lastCode && s.RegionID == lastRegion).OrderBy(s => s.CountryName).ThenBy(s => s.TournamentName))
                                {
                                    if (lastCountry != pais.Country)
                                    {
                                        CountryDTO       country = new CountryDTO();
                                        List <LeagueDTO> leagues = new List <LeagueDTO>();

                                        lastCountry  = pais.Country;
                                        country.Code = pais.Country;
                                        country.Flag = pais.MenuFlagKey;
                                        country.Name = pais.CountryName;
                                        #region Ligas
                                        foreach (var liga in sports.Where(s => s.Code == lastCode && s.RegionID == lastRegion && s.Country == lastCountry).OrderBy(s => s.TournamentName))
                                        {
                                            LeagueDTO league = new LeagueDTO();
                                            league.Code = liga.TournamentID;
                                            league.Name = liga.TournamentName == "" ? liga.InternalName : liga.TournamentName;
                                            leagues.Add(league);
                                        }
                                        #endregion
                                        country.Leagues = leagues;
                                        countries.Add(country);
                                    }
                                }
                                #endregion
                                newRegion.Countries = countries;
                                regions.Add(newRegion);
                            }
                        }
                        viewSport.Regions = regions;

                        sportsDto.Add(viewSport);
                    }
                }
                return(sportsDto);
            }
            return(new List <SportDTO>());
        }
コード例 #5
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));
        }
コード例 #6
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));
            }
        }