Ejemplo n.º 1
0
        public async Task <IListModelResponse <LeagueDto> > GetTeamLeaguesAsync(int teamId)
        {
            Logger?.LogInformation($"{nameof(GetTeamLeaguesAsync)} has been invoked");

            var response = new ListModelResponse <LeagueDto>();

            try
            {
                var team = await TeamRepository.GetItemByIdAsync(teamId);

                if (team == null)
                {
                    throw new FlmException($"Team with id={teamId} doesn't exist");
                }

                var query = LeagueRepository.GetTeamLeagueAssignments()
                            .Where(assignment => assignment.TeamId == teamId)
                            .Select(assignment => assignment.League);

                response.Model = await query.ProjectTo <LeagueDto>().ToListAsync();
            }
            catch (Exception ex)
            {
                response.SetError(ex, Logger);
            }

            return(response);
        }
Ejemplo n.º 2
0
        public async Task <IListModelResponse <PlayerLookupDto> > LookupPlayerAsync(string searchCriteria)
        {
            Logger?.LogInformation($"{nameof(LookupPlayerAsync)} [{searchCriteria}] has been invoked");

            var response = new ListModelResponse <PlayerLookupDto>();

            try
            {
                var keywords = searchCriteria.ToLower().GetWords();

                var query = PlayerRepository.GetItems().Where(
                    player => keywords.All(keyword =>
                                           player.FirstName.ToLower().Contains(keyword) ||
                                           player.LastName.ToLower().Contains(keyword)
                                           )
                    );

                query = query.OrderBy(entity => entity.CreationDateTime).AsNoTracking();

                query = query.Paging(LookupMaxItems, 1);
                var items = query.Select(item => Mapper.Map <PlayerLookupDto>(item));
                response.Model = await items.ToListAsync();
            }
            catch (Exception ex)
            {
                response.SetError(ex, Logger);
            }

            return(response);
        }
Ejemplo n.º 3
0
        public async Task <IListModelResponse <TeamLookupDto> > LookupTeamAsync(string searchCriteria)
        {
            Logger?.LogInformation($"{nameof(LookupTeamAsync)} [{searchCriteria}] has been invoked");

            var response = new ListModelResponse <TeamLookupDto>();

            try
            {
                var keywords = searchCriteria.ToLower().GetWords();

                var query = TeamRepository.GetItems().Where(
                    team => keywords.All(keyword =>
                                         team.Name.ToLower().Contains(keyword) ||
                                         team.City.ToLower().Contains(keyword)
                                         )
                    );

                query = query.OrderBy(entity => entity.CreationDateTime).AsNoTracking();

                query          = query.Paging(lookupMaxItems, 1);
                response.Model = await query.ProjectTo <TeamLookupDto>().ToListAsync();
            }
            catch (Exception ex)
            {
                response.SetError(ex, Logger);
            }

            return(response);
        }
        public async Task <IListModelResponse <Employee> > GetEmployeesAsync(Int32 pageSize = 0, Int32 pageNumber = 0)
        {
            Logger?.LogInformation("{0} has been invoked", nameof(GetEmployeesAsync));

            var response = new ListModelResponse <Employee>() as IListModelResponse <Employee>;

            try
            {
                response.Model = await HumanResourcesRepository.GetEmployees(pageSize, pageNumber).ToListAsync();
            }
            catch (Exception ex)
            {
                response.SetError(ex, Logger);
            }

            return(response);
        }
Ejemplo n.º 5
0
        public async Task <IListModelResponse <Warehouse> > GetWarehousesAsync(Int32 pageSize, Int32 pageNumber)
        {
            Logger?.LogInformation("{0} has been invoked", nameof(GetWarehousesAsync));

            var response = new ListModelResponse <Warehouse>() as IListModelResponse <Warehouse>;

            try
            {
                response.Model = await ProductionRepository.GetWarehouses(pageSize, pageNumber).ToListAsync();
            }
            catch (Exception ex)
            {
                response.SetError(ex, Logger);
            }

            return(response);
        }
Ejemplo n.º 6
0
        public async Task <IListModelResponse <Shipper> > GetShippersAsync(Int32 pageSize, Int32 pageNumber)
        {
            Logger?.LogInformation("{0} has been invoked", nameof(GetShippersAsync));

            var response = new ListModelResponse <Shipper>();

            try
            {
                response.Model = await SalesRepository.GetShippers(pageSize, pageNumber).ToListAsync();
            }
            catch (Exception ex)
            {
                response.SetError(ex, Logger);
            }

            return(response);
        }
Ejemplo n.º 7
0
        public async Task <IListModelResponse <Farm> > GetFarmsAsync(int pageSize, int pageNumber)
        {
            {
                Logger?.LogInformation("{0} has been invoked", nameof(GetFarmsAsync));

                var response = new ListModelResponse <Farm>();

                try
                {
                    response.Model = await FarmRepository.GetFarmsAsync(pageSize, pageNumber);
                }
                catch (Exception ex)
                {
                    response.SetError(ex, Logger);
                }

                return(response);
            }
        }
Ejemplo n.º 8
0
        public async Task <IListModelResponse <OrderInfo> > GetOrdersAsync(Int32 pageSize, Int32 pageNumber, Int32?customerID = null, Int32?employeeID = null, Int32?shipperID = null)
        {
            Logger?.LogInformation("{0} has been invoked", nameof(GetOrdersAsync));

            var response = new ListModelResponse <OrderInfo>() as IListModelResponse <OrderInfo>;

            try
            {
                response.PageSize   = pageSize;
                response.PageNumber = pageNumber;

                response.Model = await SalesRepository.GetOrders(pageSize, pageNumber, customerID, employeeID, shipperID).ToListAsync();
            }
            catch (Exception ex)
            {
                response.SetError(ex, Logger);
            }

            return(response);
        }
Ejemplo n.º 9
0
        public async Task <IListModelResponse <MatchListItemDto> > GetRoundScheduleAsync(int leagueId, byte roundNum)
        {
            Logger?.LogInformation($"{nameof(GetRoundScheduleAsync)} has been invoked");

            var response = new ListModelResponse <MatchListItemDto>();

            try
            {
                var league = await GetAndValidateItem(leagueId, roundNum);

                var matches = MatchRepository.GetItems()
                              .Where(m => m.LeagueId == leagueId && m.Round == roundNum);

                response.Model = matches.ProjectTo <MatchListItemDto>().ToList();
            }
            catch (Exception ex)
            {
                response.SetError(ex, Logger);
            }

            return(response);
        }
Ejemplo n.º 10
0
        public async Task <IListModelResponse <LeagueTeamDto> > GetLeagueTeamsAsync(int leagueId)
        {
            Logger?.LogInformation($"{nameof(GetLeagueTeamsAsync)} has been invoked");

            var response = new ListModelResponse <LeagueTeamDto>();

            try
            {
                var league = await GetAndValidateItem(leagueId);

                var query = LeagueRepository.GetTeamLeagueAssignments()
                            .Where(tla => tla.LeagueId == leagueId);

                response.Model = query.ProjectTo <LeagueTeamDto>().ToList();
            }
            catch (Exception ex)
            {
                response.SetError(ex, Logger);
            }

            return(response);
        }
Ejemplo n.º 11
0
        public async Task <IListModelResponse <TeamTableStandingDto> > GetStandingsAsync(int leagueId)
        {
            Logger?.LogInformation($"{nameof(GetStandingsAsync)} has been invoked");

            var response = new ListModelResponse <TeamTableStandingDto>();

            try
            {
                var league = await GetAndValidateItem(leagueId);

                var query = LeagueRepository.GetStandings()
                            .Where(tts => tts.LeagueId == leagueId)
                            .OrderBy(tts => tts.Position);

                response.Model = await query.ProjectTo <TeamTableStandingDto>().ToListAsync();
            }
            catch (Exception ex)
            {
                response.SetError(ex, Logger);
            }

            return(response);
        }
Ejemplo n.º 12
0
        public async Task <IListModelResponse <MatchListItemDto> > EditRoundScheduleAsync(int leagueId, byte roundNum, IEnumerable <Match> matches)
        {
            Logger?.LogInformation($"{nameof(EditRoundScheduleAsync)} has been invoked");

            var response = new ListModelResponse <MatchListItemDto>();

            try
            {
                var league = await GetAndValidateItem(leagueId, roundNum);

                var oldScheduleMatches = MatchRepository.GetItems().Where(m => m.LeagueId == leagueId && m.Round == roundNum);
                await MatchRepository.RemoveItemsAsync(oldScheduleMatches);

                await MatchRepository.AddItemsAsync(matches);

                response.Model = matches.Select(item => Mapper.Map <MatchListItemDto>(item)).ToList();
            }
            catch (Exception ex)
            {
                response.SetError(ex, Logger);
            }

            return(response);
        }