Exemple #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,PersonId,SportId,DateTimeStart,DateTimeEnd,TimeSpent")] SportsLog sportsLog)
        {
            if (id != sportsLog.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(sportsLog);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SportsLogExists(sportsLog.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PersonId"] = new SelectList(_context.Person, "Id", "Id", sportsLog.PersonId);
            ViewData["SportId"]  = new SelectList(_context.Sport, "Id", "Id", sportsLog.SportId);
            return(View(sportsLog));
        }
Exemple #2
0
        public async Task <IActionResult> Create([Bind("Id,PersonId,SportId,DateTimeStart,DateTimeEnd,TimeSpent")] SportsLog sportsLog)
        {
            if (ModelState.IsValid)
            {
                _context.Add(sportsLog);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PersonId"] = new SelectList(_context.Person, "Id", "Id", sportsLog.PersonId);
            ViewData["SportId"]  = new SelectList(_context.Sport, "Id", "Id", sportsLog.SportId);
            return(View(sportsLog));
        }