Exemple #1
0
        public IActionResult Create(SeasonCreateViewModel model)
        {
            if (!User.IsInRole("Admin"))
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (model == null)
            {
                StatusMessage = "Error. Something went wrong.";
                return(View(model));
            }
            if (ModelState.IsValid)
            {
                SeasonDTO season = Mapper.Map <SeasonDTO>(model);

                var result = _seasonRepository.AddSeason(season);
                if (result == 1)
                {
                    StatusMessage = "Succesfully created.";
                    return(RedirectToAction(nameof(Index)));
                }
                if (result == -1)
                {
                    StatusMessage       = "Error. This date is already taken";
                    model.StatusMessage = StatusMessage;
                    return(View(model));
                }
                return(RedirectToAction(nameof(Index)));
            }
            StatusMessage = "Error. Data that you entered is not valid.";
            return(View(model));
        }
Exemple #2
0
        public int UpdateSeason(SeasonDTO season)
        {
            Season seasonNew = Mapper.Map <Season>(season);
            var    seasons   = _context.Season.Where(s => s.IsDeleted != true && s.Id != season.Id);

            foreach (var existingSeason in seasons)
            {
                if (!(seasonNew.EndDate <= existingSeason.StartDate || seasonNew.StartDate >= existingSeason.EndDate))
                {
                    return(-1);
                }
                if (!(seasonNew.ConferenceEndDate <= existingSeason.ConferenceStartDate || seasonNew.ConferenceStartDate >= existingSeason.ConferenceEndDate))
                {
                    return(-1);
                }
            }
            var seasonToUpdate = _context.Season.Find(season.Id);

            seasonToUpdate.MainImageFileName   = seasonNew.MainImageFileName;
            seasonToUpdate.StartDate           = seasonNew.StartDate;
            seasonToUpdate.EndDate             = seasonNew.EndDate;
            seasonToUpdate.ConferenceStartDate = seasonNew.ConferenceStartDate;
            seasonToUpdate.ConferenceEndDate   = seasonNew.ConferenceEndDate;
            seasonToUpdate.EditionNumber       = seasonNew.EditionNumber;
            seasonToUpdate.Location            = seasonNew.Location;
            seasonToUpdate.IsDeleted           = seasonNew.IsDeleted;
            seasonToUpdate.Name = seasonNew.Name;


            int result = _context.SaveChanges();

            return(result);
        }
Exemple #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SeasonCI"/> class
        /// </summary>
        /// <param name="dto">The <see cref="SeasonDTO"/> used to create new instance</param>
        /// <param name="culture">A <see cref="CultureInfo"/> specifying the language of the season info</param>
        public SeasonCI(SeasonDTO dto, CultureInfo culture)
        {
            Guard.Argument(dto, nameof(dto)).NotNull();
            Guard.Argument(culture, nameof(culture)).NotNull();

            Names = new Dictionary <CultureInfo, string>();
            Merge(dto, culture);
        }
Exemple #4
0
 private static void ValidateSeasonExtended(seasonExtended msg, SeasonDTO dto)
 {
     Assert.AreEqual(msg.id, dto.Id.ToString());
     Assert.AreEqual(msg.name, dto.Name);
     Assert.AreEqual(msg.start_date, dto.StartDate);
     Assert.AreEqual(msg.end_date, dto.EndDate);
     Assert.AreEqual(msg.year, dto.Year);
 }
Exemple #5
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="SeasonCI" /> class
        /// </summary>
        /// <param name="dto">The <see cref="SeasonDTO" /> used to create new instance</param>
        /// <param name="culture">A <see cref="CultureInfo" /> specifying the language of the season info</param>
        public SeasonCI(SeasonDTO dto, CultureInfo culture)
            : base(dto)
        {
            Contract.Requires(dto != null);
            Contract.Requires(culture != null);

            _name = new Dictionary <CultureInfo, string>();
            Merge(dto, culture);
        }
Exemple #6
0
        /// <summary>
        /// Merges the information from the provided <see cref="SeasonDTO"/> to the current instance
        /// </summary>
        /// <param name="season">A <see cref="SeasonDTO"/> containing season info</param>
        /// <param name="culture">A <see cref="CultureInfo"/> specifying the language of the season info</param>
        public void Merge(SeasonDTO season, CultureInfo culture)
        {
            Guard.Argument(season, nameof(season)).NotNull();
            Guard.Argument(culture, nameof(culture)).NotNull();

            StartDate      = season.StartDate;
            EndDate        = season.EndDate;
            Year           = season.Year;
            _name[culture] = season.Name;
        }
Exemple #7
0
        /// <summary>
        ///     Merges the information from the provided <see cref="SeasonDTO" /> to the current instance
        /// </summary>
        /// <param name="season">A <see cref="SeasonDTO" /> containing season info</param>
        /// <param name="culture">A <see cref="CultureInfo" /> specifying the language of the season info</param>
        public void Merge(SeasonDTO season, CultureInfo culture)
        {
            Contract.Requires(season != null);
            Contract.Requires(culture != null);

            StartDate      = season.StartDate;
            EndDate        = season.EndDate;
            Year           = season.Year;
            _name[culture] = season.Name;
        }
        public async Task <IActionResult> Put(Guid id, [FromBody] SeasonDTO value)
        {
            if (id != value.Id)
            {
                return(this.BadRequest("Posted season Id does not match the request."));
            }
            IActionResult result = await Execute(_log, async() => await _seasonService.Upsert(value));

            return(result);
        }
        /// <summary>
        /// Creates the specified season.
        /// </summary>
        /// <param name="seasonDto">The entity.</param>
        /// <returns>The season that was created.</returns>
        public async Task <SeasonDTO> Create(SeasonDTO seasonDto)
        {
            var result = await this.Handler.Execute(_log, async() =>
            {
                Season season = _seasonFactory.CreateDomainObject(seasonDto);
                season.Validate();

                season = await _seasonRepository.Create(season);
                return(_seasonMapper.ToDto(season));
            });

            return(result);
        }
Exemple #10
0
        public void UpdateSeason(int id, [FromBody] SeasonDTO updatedSeason)
        {
            Season item = _unitOfWork.GetRepository <Season>().Single(x => x.Id == id);

            if (item != null)
            {
                item.Name      = updatedSeason.Name;
                item.StartDate = updatedSeason.StartDate;
                item.EndDate   = updatedSeason.EndDate;

                _unitOfWork.GetRepository <Season>().Update(item);
                _unitOfWork.SaveChanges();
            }
        }
Exemple #11
0
        public IHttpActionResult CreateSeason([FromBody] SeasonDTO _season)
        {
            season s = new season()
            {
                description = _season.Description, league = (int)_season.League, dateFrom = DateTime.Now, dateTo = new DateTime(2016, 04, 29), title = _season.Title
            };

            using (var context = new escorcenterdbEntities())
            {
                context.seasons.Add(s);
                context.SaveChanges();
            }
            return(Ok(s));
        }
Exemple #12
0
 public void AddSeason([FromBody] SeasonDTO newSeason)
 {
     try
     {
         _unitOfWork.GetRepository <Season>().Insert(new Season()
         {
             Name      = newSeason.Name,
             StartDate = newSeason.StartDate,
             EndDate   = newSeason.EndDate
         });
         _unitOfWork.SaveChanges();
     }
     catch (Exception ex)
     {
         //TODO Logger implementation
     }
 }
Exemple #13
0
        public int AddSeason(SeasonDTO season)
        {
            Season newSeason = Mapper.Map <Season>(season);
            var    seasons   = _context.Season.Where(s => s.IsDeleted != true);

            foreach (var existingSeason in seasons)
            {
                if (!(newSeason.EndDate <= existingSeason.StartDate || newSeason.StartDate >= existingSeason.EndDate))
                {
                    return(-1);
                }
            }

            var status = _context.Season.Add(newSeason);

            int result = _context.SaveChanges();

            return(result);
        }
        public IHttpActionResult GetPastMatchesByLeagueId(long leagueId)
        {
            DateTime now      = DateTime.Now;
            long     seasonId = GetCurrentSeasonId(leagueId, now);

            if (seasonId < 0)
            {
                return(Ok());
            }

            season         _season = null;
            List <WeekDTO> weeks   = new List <WeekDTO>();

            using (var context = new escorcenterdbEntities())
            {
                week[] _weeks = (from w in context.weeks where w.enabled == true && w.season == seasonId && w.dateFrom <= now select w).OrderByDescending(w => w.dateFrom).ToArray <week>();
                foreach (week _week in _weeks)
                {
                    WeekDTO week = GetPastMatchesByWeekId(_week.id, now);
                    if (week != null)
                    {
                        weeks.Add(week);
                    }
                }
                _season = (from s in context.seasons where s.id == seasonId select s).FirstOrDefault <season>();
            }
            if (_season == null)
            {
                return(Ok());
            }
            SeasonDTO season = new SeasonDTO
            {
                Title       = _season.title,
                DateFrom    = _season.dateFrom.ToString(),
                DateTo      = _season.dateTo.ToString(),
                Description = _season.description,
                Id          = _season.id,
                League      = _season.league
            };

            season.Weeks.AddRange(weeks);
            return(Ok(season));
        }
Exemple #15
0
        public async Task <int> UpdateSeason(SeasonDTO value)
        {
            Seasons season;

            season = GetSeason(value.Id);
            if (season != null)
            {
                season.DescriptionSeason = value.descriptionSeason;
                season.Startdate         = (DateTime)value.StartDate;
                season.Enddate           = (DateTime)value.EndDate;
                _context.Update(season);
                await _context.SaveChangesAsync();

                return(200);
            }
            else
            {
                return(400);
            }
        }
        public async Task <ActionResult> Insert([FromBody] SeasonDTO value)
        {
            string user_id = Request.Headers.FirstOrDefault(header => header.Key == "user_id").Value;

            if (_repository.ValidateUser(user_id, 2))
            {
                var resul = await _repository.Insert(value);

                if (resul == 200)
                {
                    return(Ok());
                }
                else
                {
                    return(BadRequest("Already exists"));
                }
            }
            else
            {
                return(Unauthorized("You have no permission to perform this action"));
            }
        }
Exemple #17
0
        public async Task <int> Insert(SeasonDTO value)
        {
            Seasons season;

            season = GetSeason(value.Id);

            if (season == null)
            {
                season            = new Seasons();
                season.Active     = true;
                season.Typeseason = 1;
                season.Startdate  = (DateTime)value.StartDate;
                season.Enddate    = (DateTime)value.EndDate;

                _context.Seasons.Add(season);
                await _context.SaveChangesAsync();

                return(200);
            }
            else
            {
                return(400);
            }
        }
Exemple #18
0
 public Season CreateDomainObject(SeasonDTO dto)
 {
     return(new Season(dto.Id, dto.Name, dto.CreatedOn, dto.Year, dto.LeagueId));
 }
Exemple #19
0
        private async Task <GameDTO> SaveGame(GamePageInformation gameInfo, TeamDTO awayTeam, TeamDTO homeTeam, SeasonDTO season)
        {
            GameDTO gameDto = new GameDTO()
            {
                AwayTeamId   = awayTeam.Id,
                HomeTeamId   = homeTeam.Id,
                Date         = gameInfo.Date,
                Time         = gameInfo.Time,
                Location     = gameInfo.Location,
                SeasonId     = season.Id,
                CreatedOnUtc = DateTime.Now
            };

            return(await _gameService.Upsert(gameDto));
        }
        public IHttpActionResult GetResultTable(int leagueId)
        {
            long seasonId = GetCurrentSeasonId(leagueId, DateTime.Now);

            if (seasonId == 0)
            {
                return(Ok());
            }

            scoretableview[]           _scoreTable = null;
            season                     _season     = null;
            List <ScoreTableResultDTO> scoreTable  = new List <ScoreTableResultDTO>();

            using (var context = new escorcenterdbEntities())
            {
                _scoreTable = (from st in context.scoretableviews where st.season == seasonId select st).OrderBy(st => st.GamesWon.Value * 3 + st.GamesDrawn.Value * 1).ToArray <scoretableview>();
                _season     = (from s in context.seasons where s.id == seasonId && s.enabled == true select s).FirstOrDefault <season>();

                if (_scoreTable == null || _season == null)
                {
                    return(NotFound());
                }

                foreach (scoretableview st in _scoreTable)
                {
                    team _team = (from t in context.teams where t.Id == st.team select t).FirstOrDefault <team>();

                    String leagueName          = getLeagueNameById(_team.League);
                    ScoreTableResultDTO result = new ScoreTableResultDTO
                    {
                        Team        = AutoMapper.Mapper.Map <team, TeamDTO>(_team),
                        GamesDrawn  = st.GamesDrawn.Value,
                        GamesLost   = st.GamesLost.Value,
                        GamesPlayed = st.GamesPlayed.Value,
                        GamesWined  = st.GamesWon.Value,
                        //Cambiar esto a hacerlo dinamico, no solo para el fut
                        Points          = st.GamesWon.Value * 3 + st.GamesDrawn.Value * 1,
                        ScoreAgainst    = (long)st.ScoreAgainst.Value,
                        ScoreDifference = (long)st.ScoreDifference.Value,
                        ScoreFavor      = (long)st.ScoreFavor.Value,
                        League          = leagueName
                    };

                    scoreTable.Add(result);
                }
            }
            if (_season == null)
            {
                return(Ok());
            }

            scoreTable.OrderBy(r => r.Points);

            SeasonDTO season = new SeasonDTO
            {
                DateFrom    = _season.dateFrom.ToString(),
                DateTo      = _season.dateTo.ToString(),
                Description = _season.description,
                Id          = _season.id,
                League      = _season.league,
                Title       = _season.title
            };

            season.ScoreTableResult.AddRange(scoreTable);
            return(Ok(season));
        }
        public async Task <IActionResult> Post([FromBody] SeasonDTO value)
        {
            IActionResult result = await Execute(_log, async() => await _seasonService.Upsert(value));

            return(result);
        }