public async Task Persist(Venue venue)
 {
     DatabaseContext context = new DatabaseContext();
     context.Venues.Add(venue);
     await context.SaveChangesAsync().ConfigureAwait(false);
     //context.Dispose();
 }
        public async Task<IList<Match>> GetMatches(int? take, int? skip, string searchWord)
        {
            DatabaseContext context = new DatabaseContext();

            IQueryable<Match> query = context.Matches.Where(x => !x.Canceled).OrderBy(x => x.StartDate);

            if (!string.IsNullOrEmpty(searchWord))
            {
                Boxer boxer = await context.Boxers.FirstOrDefaultAsync(x => x.Name == searchWord);
                Venue venue = await context.Venues.FirstOrDefaultAsync(x => x.Name == searchWord);

                if (boxer != null)
                {
                    query = venue != null
                        ? query.Where(x => x.BoxerOneId == boxer.Id || x.BoxerTwoId == boxer.Id || x.VenueId == venue.Id)
                        : query.Where(x => x.BoxerOneId == boxer.Id || x.BoxerTwoId == boxer.Id);
                }
                else if (venue != null)
                {
                    query = query.Where(x => x.VenueId == venue.Id);
                }
            }

            return await query.ToListAsync().ConfigureAwait(false);
        }
 public async Task Delete(int id)
 {
     DatabaseContext context = new DatabaseContext();
     context.Venues.Remove(context.Venues.FirstOrDefault(x => x.Id == id));
     await context.SaveChangesAsync().ConfigureAwait(false);
     //context.Dispose();
 }
 public async Task PersistUser(User user)
 {
     DatabaseContext context = new DatabaseContext();
     context.Users.Add(user);
     await context.SaveChangesAsync().ConfigureAwait(false);
     //context.Dispose();
 }
 public async Task Persist(Match match)
 {
     using (DatabaseContext context = new DatabaseContext())
     {
         context.Matches.Add(match);
         await context.SaveChangesAsync().ConfigureAwait(false);
     }
 }
예제 #6
0
        public async Task CancelBet(int betId)
        {
            DatabaseContext context = new DatabaseContext();
            var bet = context.Bets.FirstOrDefault(x => x.Id == betId);
            if (bet != null)
            {
                bet.Canceled = true;
            }

            await context.SaveChangesAsync().ConfigureAwait(false);
        }
        public async Task DeleteUser(int id)
        {
            DatabaseContext context = new DatabaseContext();
            User user = context.Users.FirstOrDefault(x => x.Id == id);
            if (user != null)
            {
                user.Deleted = true;
            }

            await context.SaveChangesAsync().ConfigureAwait(false);
            //context.Dispose();
        }
        public async Task<Login> Login(string username, string password)
        {
            DatabaseContext context = new DatabaseContext();

            if (context.Users.Any(x => x.Username == username && x.Password == password && !x.Deleted))
            {
                await context.Logins.Where(x => x.IsExpired).ForEachAsync(x => x.IsExpired = true).ConfigureAwait(false);
                context.Logins.Add(new Login() { ExpiryDate = DateTime.Now + new TimeSpan(1, 0, 0), IsExpired = false });
                await context.SaveChangesAsync().ConfigureAwait(false);
            }

            return await context.Logins.FirstOrDefaultAsync(x => x.ExpiryDate < DateTime.Now).ConfigureAwait(false);
        }
        public async Task DeleteById(int id)
        {
            DatabaseContext context = new DatabaseContext();

            var match = context.Matches.FirstOrDefault(x => x.Id == id);
            if (match != null)
            {
                match.Canceled = true;
            }

            await m_BetRepository.CancelAllBetsByMatchId(id).ConfigureAwait(false);

            await context.SaveChangesAsync().ConfigureAwait(false);
            //context.Dispose();
        }
 public async Task Persist(Boxer boxer)
 {
     DatabaseContext context = new DatabaseContext();
     context.Boxers.Add(boxer);
     await context.SaveChangesAsync().ConfigureAwait(false);
 }
예제 #11
0
 public async Task CancelAllBetsByMatchId(int matchId)
 {
     DatabaseContext context = new DatabaseContext();
     context.Bets.ToListAsync().Result.ForEach(x => x.Canceled = true);
     await context.SaveChangesAsync().ConfigureAwait(false);
 }
 public async Task Cancel(int matchId)
 {
     DatabaseContext context = new DatabaseContext();
     context.Bets.Where(x => x.MatchId == matchId).ToList().ForEach(x => x.Canceled = true);
     await context.SaveChangesAsync().ConfigureAwait(false);
 }