public async Task <double> CloseRoulette(int rouletteId)
        {
            try
            {
                double sumAmount      = 0;
                var    optionsBuilder = new DbContextOptionsBuilder <RouletteContext>();
                optionsBuilder.UseSqlServer("RouletteContext");
                using var context = new RouletteContext(optionsBuilder.Options);
                var rouletteGet = await context.Roulette.FirstOrDefaultAsync(x => x.Id == rouletteId);

                if (rouletteGet != null)
                {
                    rouletteGet.State = Convert.ToInt32(StateGame.Close);
                }
                rouletteGet.DateEnd = DateTime.Now;
                if (await UpdateRoulette(rouletteGet))
                {
                    var listBet = _betService.ListBet(rouletteId);
                    foreach (var item in listBet)
                    {
                        sumAmount += item.Amount;
                    }
                }

                return(sumAmount);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public List <Bet> ListBet(int rouletteId)
 {
     try
     {
         var optionsBuilder = new DbContextOptionsBuilder <RouletteContext>();
         optionsBuilder.UseSqlServer("RouletteContext");
         using var context = new RouletteContext(optionsBuilder.Options);
         return(context.Bet.Where(x => x.RouletteId == rouletteId).ToList());
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public Entities.Roulette GetRoulette(int rouletteId)
        {
            try
            {
                var optionsBuilder = new DbContextOptionsBuilder <RouletteContext>();
                optionsBuilder.UseSqlServer("RouletteContext");
                using var context = new RouletteContext(optionsBuilder.Options);

                return(context.Roulette.FirstOrDefault(x => x.Id == rouletteId));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #4
0
        public async Task <User> Authenticate(string username, string password)
        {
            try
            {
                var optionsBuilder = new DbContextOptionsBuilder <RouletteContext>();
                optionsBuilder.UseSqlServer("RouletteContext");
                using var context = new RouletteContext(optionsBuilder.Options);

                return(await context.User.FirstOrDefaultAsync(x => x.UserName == username && x.Password == password));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public async Task <bool> UpdateRoulette(Entities.Roulette roulette)
 {
     try
     {
         var optionsBuilder = new DbContextOptionsBuilder <RouletteContext>();
         optionsBuilder.UseSqlServer("RouletteContext");
         using (var context = new RouletteContext(optionsBuilder.Options))
         {
             context.Entry(roulette).State = EntityState.Modified;
             return(await context.SaveChangesAsync() > 0);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public async Task <int> SaveBet(Entities.Bet gameBet)
        {
            try
            {
                var optionsBuilder = new DbContextOptionsBuilder <Data.Context.RouletteContext>();
                optionsBuilder.UseSqlServer("RouletteContext");
                using var context = new RouletteContext(optionsBuilder.Options);
                context.Bet.Add(gameBet);
                if (await context.SaveChangesAsync() > 0)
                {
                    return(gameBet.Id);
                }

                return(0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async Task <List <Entities.Roulette> > ListRoulette()
        {
            try
            {
                var optionsBuilder = new DbContextOptionsBuilder <RouletteContext>();
                optionsBuilder.UseSqlServer("RouletteContext");
                using var context = new RouletteContext(optionsBuilder.Options);
                var listResult = await context.Roulette.ToListAsync();

                if (listResult != null && listResult.Count > 0)
                {
                    foreach (var item in listResult)
                    {
                        item.StateDesc = StateGameDes[item.State];
                    }
                }
                return(listResult);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #8
0
 public RouletteService(RouletteContext context, ILogger <RouletteService> logger)
 {
     _context = context;
     _logger  = logger;
 }
 public RoulettesController(RouletteContext context)
 {
     _context = context;
 }
 public RoulettesController(IRouletteRepository rouletterepository, RouletteContext context)
 {
     _rouletterepository = rouletterepository;
     _context            = context;
 }
Example #11
0
 public RoulleteDAL(RouletteContext context)
 {
     _context = context;
 }
 public RouletteRepository(RouletteContext dbContext)
 {
     _dbContext = dbContext;
 }
Example #13
0
 public RouletteRepository(RouletteContext context)
 {
     _context = context;
 }
Example #14
0
 public CrudBet(RouletteContext betContext, IConnectionMultiplexer redis)
 {
     _betContext   = betContext;
     _redisService = redis;
 }
Example #15
0
 public RoulettesController(RouletteContext context, BetContext contextBet, UserContext contextUser)
 {
     _contextUser = contextUser;
     _contextBet  = contextBet;
     _context     = context;
 }
Example #16
0
 public BetsController(BetContext context, UserContext contextUser, RouletteContext contextRoulette)
 {
     _contextUser     = contextUser;
     _contextRoulette = contextRoulette;
     _context         = context;
 }
Example #17
0
 public CrudRoulette(RouletteContext rouletteContext, IConnectionMultiplexer redis)
 {
     _rouletteContext = rouletteContext;
     _redisService    = redis;
 }
 public RoulettesController(RouletteContext context, IConnectionMultiplexer redis)
 {
     _rouletteContext = context;
     _redisService    = redis;
     _crudRoulette    = new CrudRoulette(_rouletteContext, _redisService);
 }
Example #19
0
 public BetService(IRouletteService rouletteService, RouletteContext context, ILogger <BetService> logger)
 {
     _rouletteService = rouletteService;
     _context         = context;
     _logger          = logger;
 }