Ejemplo n.º 1
0
        public async Task <int> UpdateAsync(Student student)
        {
            _context.Attach(student).State = EntityState.Modified;
            int changes = await _context.SaveChangesAsync();

            return(await Task.FromResult(changes));
        }
Ejemplo n.º 2
0
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Course).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CourseExists(Course.CourseID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 3
0
        public IActionResult OnPostEdit()
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            _context.Attach(Student).State = EntityState.Modified;

            try
            {
                _context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StudentExists(Student.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(View("List", _context.Student.ToList()));
        }
Ejemplo n.º 4
0
        public ActionResult DeleteStudent(long studentId)
        {
            var student = new Student
            {
                StudentId = studentId
            };

            _dbContext.Attach(student);
            _dbContext.Remove(student);
            _dbContext.SaveChanges();

            return(Ok());
        }
Ejemplo n.º 5
0
        public ActionResult DeleteInstructor(long instructorId)
        {
            var instructor = new Instructor
            {
                InstructorId = instructorId
            };

            _dbContext.Attach(instructor);
            _dbContext.Remove(instructor);
            _dbContext.SaveChanges();

            return(Ok());
        }
Ejemplo n.º 6
0
        public void UpdateKabinets(SchoolContext context,
                                   int selectedKabinet, SchoolClass schoolClass)
        {
            var schoolClassKabinet = schoolClass.SchoolClassKabinetAssignment.KabinetId;

            context.Attach(schoolClass).State = EntityState.Modified;
            context.Remove(schoolClass.SchoolClassKabinetAssignment);

            schoolClass.SchoolClassKabinetAssignment =
                new SchoolClassKabinetAssignment()
            {
                KabinetId     = schoolClass.Id,
                SchoolClassId = selectedKabinet
            };
        }
Ejemplo n.º 7
0
        public void Update(T entity)
        {
            var avoidingAttachedEntity = GetById(entity.Id);

            _context.Entry(avoidingAttachedEntity).State = EntityState.Detached;

            var entry = _context.Entry(entity);

            if (entry.State == EntityState.Detached)
            {
                _context.Attach(entity);
            }

            _context.Entry(entity).State = EntityState.Modified;

            _context.SaveChanges();
        }