示例#1
0
        public async Task <IActionResult> Create([Bind("IdOrganisation,OrganisationName,IdRegion,OrganisationWebpage,OrganisationFoundation")] Organisation organisation)
        {
            if (organisation.OrganisationName != null)
            {
                var NameValid = _context.Organisation.Where(o => o.OrganisationName.ToUpper() == organisation.OrganisationName.ToUpper()).FirstOrDefault();
                if (NameValid != null)
                {
                    ModelState.AddModelError("OrganisationName", "Already taken!");
                }
            }
            if (organisation.OrganisationWebpage != null && !Regex.IsMatch(organisation.OrganisationWebpage, "(http://www.|https://www.|http://|https://)?[a-z0-9]+([-.]{1}[a-z0-9]+)*.[a-z]{2,5}(:[0-9]{1,5})?(/.*)?$"))
            {
                ModelState.AddModelError("OrganisationWebpage", "Invalid link");
            }
            if (organisation.OrganisationFoundation > DateTime.Today)
            {
                ModelState.AddModelError("OrganisationFoundation", "Invalid date");
            }
            if (ModelState.IsValid)
            {
                _context.Add(organisation);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdRegion"] = new SelectList(_context.Region, "IdRegion", "RegionName");
            return(View(organisation));
        }
        public async Task <IActionResult> Create([Bind("IdSubdivision,IdOrganisation,SubdivisionName,SubdivisionFoundation,IdGame")] Subdivision subdivision)
        {
            var organisation_data = await _context.Organisation.FindAsync(subdivision.IdOrganisation);

            if (subdivision.SubdivisionFoundation < organisation_data.OrganisationFoundation)
            {
                ModelState.AddModelError("SubdivisionFoundation", "Invalid date");
            }
            if (subdivision.SubdivisionFoundation > DateTime.Today)
            {
                ModelState.AddModelError("SubdivisionFoundation", "Invalid date");
            }
            var NameValid = _context.Subdivision.Where(s => s.IdOrganisation == subdivision.IdOrganisation && s.IdGame == subdivision.IdGame).FirstOrDefault();

            if (NameValid != null)
            {
                ModelState.AddModelError("IdGame", "Already created");
            }
            if (ModelState.IsValid)
            {
                var game_data = await _context.Game.FindAsync(subdivision.IdGame);

                subdivision.SubdivisionName = organisation_data.OrganisationName + " - " + game_data.GameName;
                _context.Add(subdivision);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index), new { id = subdivision.IdOrganisation }));
            }
            ViewBag.organisationID     = subdivision.IdOrganisation;
            ViewData["IdGame"]         = new SelectList(_context.Game, "IdGame", "GameName", subdivision.IdGame);
            ViewData["IdOrganisation"] = new SelectList(_context.Organisation, "IdOrganisation", "OrganisationName", subdivision.IdOrganisation);
            return(View(subdivision));
        }
        public async Task <IActionResult> Create([Bind("IdEvent,EventName,EventLocation,EventWebpage,EventPrizeFund,EventStartDate")] Event @event)
        {
            if (@event.EventName != null && Regex.IsMatch(@event.EventName, "[^a-zA-Z0-9 ]"))
            {
                ModelState.AddModelError("EventName", "Invalid characters");
            }
            if (@event.EventPrizeFund < 0)
            {
                ModelState.AddModelError("EventPrizeFund", "Uncorrect Prize");
            }
            if (@event.EventStartDate < DateTime.Today)
            {
                ModelState.AddModelError("EventStartDate", "Invalid date");
            }
            if (@event.EventWebpage != null && !Regex.IsMatch(@event.EventWebpage, "(http://www.|https://www.|http://|https://)?[a-z0-9]+([-.]{1}[a-z0-9]+)*.[a-z]{2,5}(:[0-9]{1,5})?(/.*)?$"))
            {
                ModelState.AddModelError("EventWebpage", "Invalid link");
            }
            if (ModelState.IsValid)
            {
                _context.Add(@event);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(@event));
        }
        public async Task <IActionResult> Create([Bind("IdPlayer,IdSubdivision,PlayerName,PlayerNickname,PlayerJoin,PlayerBirth")] Player player)
        {
            DateTime dateNow = DateTime.Today;
            int      year    = dateNow.Year - player.PlayerBirth.Year;

            if (dateNow.Month < player.PlayerBirth.Month ||
                (dateNow.Month == player.PlayerBirth.Month && dateNow.Day < player.PlayerBirth.Day))
            {
                year--;
            }
            if (year < 16)
            {
                ModelState.AddModelError("PlayerBirth", "Too young, only 16+");
            }
            if (player.PlayerName != null && Regex.IsMatch(player.PlayerName, "[^a-zA-Z]"))
            {
                ModelState.AddModelError("PlayerName", "Invalid characters");
            }
            if (player.PlayerNickname != null && Regex.IsMatch(player.PlayerNickname, "[^a-zA-Z0-9]"))
            {
                ModelState.AddModelError("PlayerNickname", "Invalid characters");
            }
            var subdivision_data = await _context.Subdivision.FindAsync(player.IdSubdivision);

            if (subdivision_data != null && player.PlayerJoin < subdivision_data.SubdivisionFoundation)
            {
                ModelState.AddModelError("PlayerJoin", "Subdivision has not been created in this date.");
            }
            if (player.PlayerJoin > dateNow)
            {
                ModelState.AddModelError("PlayerJoin", "You from future?");
            }
            if (player.PlayerNickname != null)
            {
                var NameValid = _context.Player.Where(o => o.PlayerNickname.ToUpper() == player.PlayerNickname.ToUpper() && o.IdPlayer != player.IdPlayer).FirstOrDefault();
                if (NameValid != null)
                {
                    ModelState.AddModelError("PlayerNickname", "Nickname already used.");
                }
            }
            if (ModelState.IsValid)
            {
                _context.Add(player);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Players", new { id = player.IdSubdivision }));
            }
            ViewBag.subdivisionId     = player.IdSubdivision;
            ViewData["IdSubdivision"] = new SelectList(_context.Subdivision, "IdSubdivision", "SubdivisionName", player.IdSubdivision);
            return(View(player));
        }
示例#5
0
        public async Task <IActionResult> Create([Bind("IdGame,GameName")] Game game)
        {
            var NameValid = _context.Game.AsNoTracking().Where(g => g.GameName.ToUpper() == game.GameName.ToUpper()).FirstOrDefault();

            if (NameValid != null)
            {
                ModelState.AddModelError("GameName", "Already added");
            }
            if (ModelState.IsValid)
            {
                _context.Add(game);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(game));
        }
示例#6
0
        public async Task <IActionResult> Create([Bind("IdSponsor,SponsorName,SponsorWebpage,SponsorFoundation")] Sponsor sponsor)
        {
            if (!Regex.IsMatch(sponsor.SponsorWebpage, "(http://www.|https://www.|http://|https://)?[a-z0-9]+([-.]{1}[a-z0-9]+)*.[a-z]{2,5}(:[0-9]{1,5})?(/.*)?$"))
            {
                ModelState.AddModelError("SponsorWebpage", "Invalid link");
            }
            if (sponsor.SponsorFoundation > DateTime.Today)
            {
                ModelState.AddModelError("SponsorFoundation", "Invalid date");
            }
            if (ModelState.IsValid)
            {
                _context.Add(sponsor);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(sponsor));
        }