Пример #1
0
        public void Create(FantasyFootballBdo fantasyFootballBdo)
        {
            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 teamEntity = TeamsRepository.GetFirstOrDefault(entity => (entity.SeasonId == _seasonId) && (entity.WeekOffset == _weekOffset));

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

            _fantasyFootballBdo = fantasyFootballBdo;

            foreach (var teamBdoPair in _fantasyFootballBdo.Teams)
            {
                AddTeam(teamBdoPair.Value);
            }
        }
        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);
        }