Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Name,Credits,LocationId,Id,CreatedDate,LastUpdatedDate")] Course course)
        {
            if (id != course.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(course);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CourseExists(course.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["LocationId"] = new SelectList(_context.Locations, "Id", "Id", course.LocationId);
            return(View(course));
        }
        public async Task <IActionResult> Edit(int id, [Bind("DeclaredMajor,FirstName,LastName,DateOfBirth,GCIdentificationNumbe,Id,CreatedDate,LastUpdatedDate")] Student student)
        {
            if (id != student.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(student);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StudentExists(student.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(student));
        }
        public IActionResult Update()
        {
            var context  = new GrandCircusLmsExampleContext();
            var location = context.Locations.FirstOrDefault();

            location.Name = "My House";
            var course    = context.Courses.Find(2);
            var newCourse = new Course
            {
                Name    = "Example",
                Credits = 2
            };

            context.Update(location);
            context.Remove(course);
            context.Add(newCourse);
            context.SaveChanges();

            return(View());
        }