Пример #1
0
        public void Edit(PocoCourse course)
        {
            if (course.InstructorsId.Count > 0)
            {
                var obj = ctx.Instructor_Course.Find(course.Id);
                foreach (int id in course.InstructorsId)
                {
                    Instructor_Course ic = new Instructor_Course()
                    {
                        id = obj.id,
                        fk_instructorid = id,
                    };

                    ctx.Instructor_Course.Attach(ic);
                    ctx.Entry(ic).State = EntityState.Modified;
                    ctx.SaveChanges();
                }
            }
            if (course.StudentsId.Count > 0)
            {
                var obj = ctx.Student_Course.Find(course.Id);
                foreach (int id in course.StudentsId)
                {
                    Student_Course sc = new Student_Course()
                    {
                        id           = obj.id,
                        fk_studentid = id,
                        fk_courseid  = course.Id
                    };
                    ctx.Entry(sc).State = EntityState.Modified;

                    ctx.SaveChanges();
                }
            }
        }
Пример #2
0
        public IHttpActionResult PutCourse(int id, Course course)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != course.id)
            {
                return(BadRequest());
            }

            db.Entry(course).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CourseExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #3
0
        public IHttpActionResult PutInstructor(int id, Instructor instructor)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != instructor.Id)
            {
                return(BadRequest());
            }

            db.Entry(instructor).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!InstructorExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }