Beispiel #1
0
        public async Task <IActionResult> Edit(int id, [Bind("IdGame,GameName")] Game game)
        {
            if (id != game.IdGame)
            {
                return(NotFound());
            }
            var NameValid = _context.Game.AsNoTracking().Where(g => g.GameName.ToUpper() == game.GameName.ToUpper() && g.IdGame != id).FirstOrDefault();

            if (NameValid != null)
            {
                ModelState.AddModelError("GameName", "Already added");
            }
            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(game);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GameExists(game.IdGame))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(game));
        }
        public async Task <IActionResult> Edit(int id, [Bind("IdSubdivision,IdOrganisation,SubdivisionName,SubdivisionFoundation,IdGame")] Subdivision subdivision)
        {
            if (id != subdivision.IdSubdivision)
            {
                return(NotFound());
            }
            var organisation_data = await _context.Organisation.FindAsync(subdivision.IdOrganisation);

            if (subdivision.SubdivisionFoundation < organisation_data.OrganisationFoundation)
            {
                ModelState.AddModelError("SubdivisionFoundation", "Organisation has not been created in this 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)
            {
                try
                {
                    var game_data = await _context.Game.FindAsync(subdivision.IdGame);

                    subdivision.SubdivisionName = organisation_data.OrganisationName + " - " + game_data.GameName;
                    _context.Update(subdivision);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SubdivisionExists(subdivision.IdSubdivision))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                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));
        }
Beispiel #3
0
 public async Task <IActionResult> Edit(int id, [Bind("IdOrganisation,OrganisationName,IdRegion,OrganisationWebpage,OrganisationFoundation")] Organisation organisation)
 {
     if (id != organisation.IdOrganisation)
     {
         return(NotFound());
     }
     if (organisation.OrganisationName != null)
     {
         var NameValid = _context.Organisation.AsNoTracking().Where(o => o.OrganisationName.ToUpper() == organisation.OrganisationName.ToUpper() && o.IdOrganisation != id).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)
     {
         try
         {
             _context.Update(organisation);
             await _context.SaveChangesAsync();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!OrganisationExists(organisation.IdOrganisation))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         return(RedirectToAction(nameof(Index)));
     }
     ViewData["IdRegion"] = new SelectList(_context.Region, "IdRegion", "RegionName");
     return(View(organisation));
 }
 public async Task <IActionResult> Edit(int id, [Bind("IdEvent,EventName,EventLocation,EventWebpage,EventPrizeFund,EventStartDate")] Event @event)
 {
     if (id != @event.IdEvent)
     {
         return(NotFound());
     }
     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)
     {
         try
         {
             _context.Update(@event);
             await _context.SaveChangesAsync();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!EventExists(@event.IdEvent))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         return(RedirectToAction(nameof(Index)));
     }
     return(View(@event));
 }
Beispiel #5
0
 public async Task <IActionResult> Edit(int id, [Bind("IdSponsor,SponsorName,SponsorWebpage,SponsorFoundation")] Sponsor sponsor)
 {
     if (id != sponsor.IdSponsor)
     {
         return(NotFound());
     }
     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)
     {
         try
         {
             _context.Update(sponsor);
             await _context.SaveChangesAsync();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!SponsorExists(sponsor.IdSponsor))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         return(RedirectToAction(nameof(Index)));
     }
     return(View(sponsor));
 }
        public async Task <IActionResult> Edit(int id, [Bind("IdPlayer,IdSubdivision,PlayerName,PlayerNickname,PlayerJoin,PlayerBirth")] Player player)
        {
            if (id != player.IdPlayer && player.IdPlayer != id)
            {
                return(NotFound());
            }

            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)
            {
                try
                {
                    _context.Update(player);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PlayerExists(player.IdPlayer))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                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));
        }