public async Task <IEnumerable <RouletteDTO> > GetRoulettesAsync()
        {
            List <RouletteDTO> rouletteList = new List <RouletteDTO>();

            using (SqlConnection connection = new SqlConnection(BaseContext.GetParameterConnection()))
            {
                await connection.OpenAsync();

                SqlCommand command = new SqlCommand(Querys.QueryGetRoulettes, connection);

                using (SqlDataReader dataReader = await command.ExecuteReaderAsync())
                {
                    while (await dataReader.ReadAsync())
                    {
                        RouletteDTO roulette = new RouletteDTO();
                        roulette.RouletteId     = Convert.ToInt32(dataReader[Constant.AttributeId]);
                        roulette.RouletteName   = Convert.ToString(dataReader[Constant.AttributeName]);
                        roulette.RouletteStatus = Convert.ToString(dataReader[Constant.AttributeIsOpen]);
                        rouletteList.Add(roulette);
                    }
                }
                await connection.CloseAsync();
            }
            return(rouletteList);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Method to get all roulette records
        /// </summary>
        /// <returns> Object with the transaction information </returns>
        public TransactionDTO <List <RouletteDTO> > GetAllRoulette()
        {
            TransactionDTO <List <RouletteDTO> > transaction = new TransactionDTO <List <RouletteDTO> >();

            transaction.Data = new List <RouletteDTO>();
            try
            {
                var getAllRoulette = _rouletteRepository.GetAllRoulette();
                if (getAllRoulette == null || getAllRoulette.Count == 0)
                {
                    transaction.Status  = Common.Status.Failure;
                    transaction.Message = "No fue posible obtener los registros de las ruletas.";

                    return(transaction);
                }
                foreach (var item in getAllRoulette)
                {
                    RouletteDTO roulette = new RouletteDTO(item.Id, item.Name, item.Code, item.AllowBets);
                    transaction.Data.Add(roulette);
                }
            }
            catch (ArgumentException ex)
            {
                transaction.Status  = Common.Status.Failure;
                transaction.Message = ex.Message;
            }

            return(transaction);
        }
Exemplo n.º 3
0
        public async Task <List <ResultsRouletteDTO> > CloseRoulette(string idRoulette)
        {
            IList <RouletteDTO> roulettes = ListRoulettes();
            IDatabase           db        = connectionMultiplexer.GetDatabase();
            RedisKey            key       = new RedisKey(nameTable);
            RouletteDTO         roulette  = roulettes.FirstOrDefault(roulettes => roulettes.Id == idRoulette);

            roulettes[roulettes.IndexOf(roulette)].Condition = Models.Enum.ConditionEnum.Close;
            await db.StringSetAsync(key, JsonConvert.SerializeObject(roulettes));

            return((List <ResultsRouletteDTO>)CalculateResults(idRoulette));
        }
Exemplo n.º 4
0
 public IActionResult Register(RouletteDTO rouletteDTO)
 {
     try
     {
         int RouletteId = 0;
         var oRoulette  = _mapper.Map <Roulette>(rouletteDTO);
         RouletteId = _rouletteRepository.RegisterRoulette(oRoulette);
         return(Ok(RouletteId));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Exemplo n.º 5
0
        private bool ValidateRoulette(string id)
        {
            bool validate = true;
            OperationsRedisRoulette db       = new OperationsRedisRoulette(connectionMultiplexer);
            RouletteDTO             roulette = db.ListRoulettes().Where(x => x.Id == id).First();

            if (roulette == null)
            {
                validate = false;
            }
            else
            {
                validate = roulette.Condition == Models.Enum.ConditionEnum.Open;
            }
            return(validate);
        }
Exemplo n.º 6
0
        public async Task <bool> CreateRoulette(RouletteDTO _roulette)
        {
            bool create = true;

            try
            {
                IDatabase           db        = connectionMultiplexer.GetDatabase();
                RedisKey            key       = new RedisKey(nameTable);
                IList <RouletteDTO> roulettes = ListRoulettes() ?? new List <RouletteDTO>();
                roulettes.Add(_roulette);
                await db.StringSetAsync(key, JsonConvert.SerializeObject(roulettes));
            }
            catch (Exception)
            {
                create = false;
            }
            return(create);
        }
Exemplo n.º 7
0
        public async Task <bool> OpenRoulette(string idRoulette)
        {
            bool update = true;

            try
            {
                IList <RouletteDTO> roulettes = ListRoulettes();
                IDatabase           db        = connectionMultiplexer.GetDatabase();
                RedisKey            key       = new RedisKey(nameTable);
                RouletteDTO         roulette  = roulettes.FirstOrDefault(roulettes => roulettes.Id == idRoulette);
                roulettes[roulettes.IndexOf(roulette)].Condition = Models.Enum.ConditionEnum.Open;
                await db.StringSetAsync(key, JsonConvert.SerializeObject(roulettes));
            }
            catch (Exception)
            {
                update = false;
            }
            return(update);
        }
Exemplo n.º 8
0
        public async Task <GeneralResponse> CreateRoulette()
        {
            try
            {
                RouletteModel rouletteModel = await GetRuletteModel() != null ? await GetRuletteModel() : new RouletteModel();

                RouletteDTO rouletteDto = new RouletteDTO();
                rouletteDto.RouletteId = new Random().Next(0, 999999999);
                rouletteModel.Roulette.Add(rouletteDto);
                await cacheService.SetUsingCache("Roulette", rouletteModel);

                GeneralResponse generalResponse = new GeneralResponse(Constants.CREACION_RULETA_EXITOSA, rouletteDto.RouletteId);

                return(generalResponse);
            }
            catch (Exception)
            {
                return(new GeneralResponse(false, Constants.CREACION_RULETA_FALLIDA));
            }
        }
Exemplo n.º 9
0
        public async Task <RouletteDTO> CreateRoulette()
        {
            RouletteDTO roulette = new RouletteDTO
            {
                Id        = Guid.NewGuid().ToString(),
                Condition = Models.Enum.ConditionEnum.Close
            };

            if (await operations.CreateRoulette(roulette))
            {
                return(roulette);
            }
            else
            {
                return new RouletteDTO
                       {
                           Id        = "NoVALIDO",
                           Condition = Models.Enum.ConditionEnum.Close
                       }
            };
        }
Exemplo n.º 10
0
        public async Task <IActionResult> CreateRoulette()
        {
            RouletteDTO newRoulette = await roulette.CreateRoulette();

            return(Ok(newRoulette.Id));
        }