public void RegisterUserOrder(string userId, OrderInfoIn orderInfoIn)
 {
     if (!_userOrderRegistry.ContainsKey(userId))
     {
         _userOrderRegistry.TryAdd(userId, orderInfoIn);
     }
     else
     {
         _userOrderRegistry[userId] = orderInfoIn;
     }
 }
 public void RegisterGuestOrder(string ipAddress, OrderInfoIn orderInfoIn)
 {
     if (!_guestOrderRegistry.ContainsKey(ipAddress))
     {
         _guestOrderRegistry.TryAdd(ipAddress, orderInfoIn);
     }
     else
     {
         _guestOrderRegistry[ipAddress] = orderInfoIn;
     }
 }
Ejemplo n.º 3
0
        public async Task <ActionResult <OrderMetadataOut> > CalculatePrice([FromBody] OrderInfoIn orderInfo)
        {
            if (ModelState.IsValid)
            {
                var orderMetadata = GetOrderMetadata(orderInfo);

                if (orderMetadata != null)
                {
                    return(Ok(orderMetadata));
                }
            }

            return(BadRequest("No such user found or Division is not eligable for boosting"));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> ProceedToPayment(OrderInfoIn orderInfo)
        {
            try
            {
                if (!this.User.Claims.Any())
                {
                    _userOrderRegistry.RegisterGuestOrder(this.HttpContext.Connection.RemoteIpAddress.ToString(), orderInfo);
                }
                else
                {
                    _userOrderRegistry.RegisterUserOrder(this.User.Claims.FirstOrDefault(z => z.Type == "sub").Value, orderInfo);
                }

                return(Ok());
            }
            catch (Exception ex)
            {
            }

            return(BadRequest());
        }
Ejemplo n.º 5
0
        private OrderMetadataOut GetOrderMetadata(OrderInfoIn orderInfo)
        {
            var summoner = _riotApiClient.GetSummonerDetailsAsync(orderInfo.Username, orderInfo.Server).Result;

            var summonerLeagues = _riotApiClient.GetLeagueDetailsAsync(summoner).Result;

            var soloQueueLeague = summonerLeagues?.FirstOrDefault(l =>
                                                                  l.QueueType.Equals(RankedSoloQueue, StringComparison.InvariantCultureIgnoreCase));

            if (soloQueueLeague != null)
            {
                Enum.TryParse(soloQueueLeague.Tier, true, out ETier tier);
                Enum.TryParse(soloQueueLeague.Rank, true, out EDivision division);

                if (_foribiddenTiers.Contains(tier))
                {
                    return(null);
                }

                var multiplier =
                    _multiplyCalculator.GetMultiplier(division, soloQueueLeague.LeaguePoints, orderInfo.OrderType);
                var rate = _tierRateRepository.Find(tier);

                var price = multiplier * rate.Price;

                return(new OrderMetadataOut
                {
                    CurrentDivision = division,
                    CurrentPoints = soloQueueLeague.LeaguePoints,
                    CurrentTier = tier,
                    Price = price
                });
            }

            return(null);
        }