コード例 #1
0
        // GET: Admin/Tournements/Delete/5
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            TournementViewModel tournementViewModel = await TournementViewModel.GetWithId(_context, id);

            if (tournementViewModel == null)
            {
                return(NotFound());
            }

            return(View(tournementViewModel));
        }
コード例 #2
0
        public async Task <IActionResult> PostTournement([FromBody] TournementViewModel tournement)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var toSave = new Tournement()
            {
                Id     = tournement.Id,
                Name   = tournement.Name,
                Nation = _context.Nations.Where(s => s.Name == tournement.Nation)?.FirstOrDefault(),
            };

            _context.Tournements.Add(toSave);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetTournement", new { id = tournement.Id }, tournement));
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("Id,Name,RegistrationStartDate,RegistrationEndDate,TournementStartDate,TournementEndDate")] TournementViewModel model)
        {
            var tournement = new Tournement();

            if (ModelState.IsValid)
            {
                tournement.Id   = model.Id;
                tournement.Name = model.Name;
                tournement.RegistrationEndDate   = model.RegistrationEndDate;
                tournement.RegistrationStartDate = model.RegistrationStartDate;
                tournement.TournementEndDate     = model.TournementEndDate;
                tournement.TournementStartDate   = model.TournementStartDate;
                _context.Add(tournement);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tournement));
        }
コード例 #4
0
        // GET: Admin/Tournements/Create
        public IActionResult Create()
        {
            var model = new TournementViewModel();

            return(View(model));
        }