Exemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("TextbookId,Name,Author,Price,CourseId")] Textbook textbook)
        {
            if (id != textbook.TextbookId)
            {
                return(RedirectToAction(nameof(Index)));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(textbook);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    TempData["message"] = $"{textbook.Name} update Failed";
                    return(RedirectToAction(nameof(Index)));
                }
                TempData["message"] = $"{textbook.Name} update Completed";
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CourseId"] = new SelectList(_context.Course, "CourseId", "CourseId", textbook.CourseId);
            return(View(textbook));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(string id, [Bind("CourseId,CourseName,CourseProf")] Course course)
        {
            if (id != course.CourseId)
            {
                return(RedirectToAction(nameof(Index)));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(course);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CourseExists(course.CourseId))
                    {
                        return(RedirectToAction(nameof(Index)));
                    }
                    else
                    {
                        TempData["message"] = $"{course.CourseName} has failed";
                        return(RedirectToAction(nameof(Index)));
                    }
                }
                TempData["message"] = $"{course.CourseName} update Completed";
                return(RedirectToAction(nameof(Index)));
            }
            return(View(course));
        }