Exemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("HikeId,MountainName,MountainId,DateHiked,TimeToSummit")] HikeLog hikeLog)
        {
            if (id != hikeLog.HikeId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(hikeLog);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!HikeLogExists(hikeLog.HikeId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MountainId"]   = new SelectList(_context.Mountain, "MountainId", "MountainName", hikeLog.MountainId);
            ViewData["MountainName"] = new SelectList(_context.Mountain, "MountainName", "MountainName", hikeLog.MountainName);
            return(View(hikeLog));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("HikeId,MountainName,MountainId,DateHiked,TimeToSummit")] HikeLog hikeLog)
        {
            if (ModelState.IsValid)
            {
                _context.Add(hikeLog);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MountainId"]   = new SelectList(_context.Mountain, "MountainId", "MountainName", hikeLog.MountainId);
            ViewData["MountainName"] = new SelectList(_context.Mountain, "MountainName", "MountainName", hikeLog.MountainName);
            return(View(hikeLog));
        }