Esempio n. 1
0
        public IActionResult Get([FromQuery] CollectionRequestModel model)
        {
            try
            {
                var query = teamsRepository.GetAll();

                if (!string.IsNullOrEmpty(model.Name))
                {
                    query = query.Where(x => x.Name.Contains(model.Name));
                }

                bool withRelations = !model.NoRelations;

                if (withRelations)
                {
                    query = this.teamsRepository.GetRelations(query) as IQueryable <Team>;
                }

                //var response = mapper.Map<Collection<TeamViewModel>>(query);

                var viewModel = query.Select(x => ViewModelHelper.BuildTeamViewModel(x, withRelations));

                return(Ok(viewModel.ToList()));
            }
            catch (Exception ex)
            {
                return(BadRequest(new JsonResult(ex.Message)));
            }
        }
Esempio n. 2
0
        public async Task GetsTeams()
        {
            using (var context = new ApplicationDbContext(_options))
            {
                context.Teams.AddRange(
                    new Team {
                    Id = 1
                },
                    new Team {
                    Id = 2
                },
                    new Team {
                    Id = 3
                });

                context.SaveChanges();
            }

            using (var context = new ApplicationDbContext(_options))
            {
                var teamsRepository = new TeamsRepository(context);

                var teams = await teamsRepository.GetAll(0, 2, null);

                Assert.Equal(2, teams.Count);
                Assert.NotNull(teams.SingleOrDefault(x => x.Id == 1));
                Assert.NotNull(teams.SingleOrDefault(x => x.Id == 2));
            }
        }
        public string Create()
        {
            string resultFile = null;

            var utcNow = DateTime.UtcNow;

            var seasonEntity = SeasonsRepository.Get(utcNow);

            if (seasonEntity == null)
            {
                throw new Exception($"There is no Fantasy Football Season covering the Date = {utcNow:yyyy-MMM-dd}.");
            }

            _seasonId = seasonEntity.SeasonId;

            _weekOffset = DateTimeHelper.GetWeekOffset(seasonEntity, utcNow);

            var firstResultsSet = TeamsRepository.GetFirstOrDefault(entity => (entity.SeasonId == _seasonId) && (entity.WeekOffset == _weekOffset));

            if (firstResultsSet == null)
            {
                throw new Exception($"There is no Weekly Results Set covering the Date = {utcNow:yyyy-MMM-dd}, otherwise known as Season Id = {_seasonId} and Week Offset = {_weekOffset}.");
            }

            _document = new Document();

            var teamEntities = TeamsRepository
                               .GetAll(_seasonId, _weekOffset);

            foreach (var teamEntity in teamEntities)
            {
                AddTeam(teamEntity);
            }

            HeaderFooter footer          = _document.Sections[0].HeadersFooters.Footer;
            Paragraph    footerParagraph = footer.AddParagraph();
            var          textRange       = footerParagraph.AppendText($"Season Id = {_seasonId} : Week Offset = {_weekOffset} : Page ");

            textRange.CharacterFormat.FontName = "Calibri";
            textRange = footerParagraph.AppendField("page number", FieldType.FieldPage);
            textRange.CharacterFormat.FontName         = "Calibri";
            footerParagraph.Format.HorizontalAlignment = HorizontalAlignment.Center;

            resultFile = $"Fantasy Football Assistant - {DateTime.UtcNow:yyyy-MMM-dd}.docx";

            _document.SaveToFile($"wwwroot\\{resultFile}", FileFormat.Docx2013);

            return(resultFile);
        }
Esempio n. 4
0
 public ActionResult Index(FootballersIndexVM model)
 {
     model.Footballers = footballersRepository.GetAll();
     model.Teams       = teamsRepository.GetAll();
     return(View(model));
 }