public IHttpActionResult PutStudent(int id, Student student)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #2
0
        public IHttpActionResult PutAssignment(int studentId, int projectId, Assignment assignment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (studentId != assignment.StudentId || projectId != assignment.ProjectId)
            {
                return(BadRequest());
            }

            //db.Entry(assignment).State = EntityState.Modified;

            //var assignmentToBeUpdated = db.Students.Find(studentId);

            var assignmentToBeUpdated = db.Assignments.FirstOrDefault(a => a.StudentId == studentId && a.ProjectId == projectId);

            db.Entry(assignmentToBeUpdated).CurrentValues.SetValues(assignment);
            db.Entry(assignmentToBeUpdated).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AssignmentExists(studentId, projectId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #3
0
        public IHttpActionResult PutProject(int id, Project project)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            //db.Entry(project).State = EntityState.Modified;

            var projectToBeUpdated = db.Projects.Find(id);

            db.Entry(projectToBeUpdated).CurrentValues.SetValues(project);
            db.Entry(projectToBeUpdated).State = EntityState.Modified;

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PutTeacher(int id, Teacher teacher)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            var dbTeacher = db.Teachers.Find(id);

            dbTeacher.FirstName    = teacher.FirstName;
            dbTeacher.LastName     = teacher.LastName;
            dbTeacher.EmailAddress = teacher.EmailAddress;
            dbTeacher.StartDate    = teacher.StartDate;
            dbTeacher.EndDate      = teacher.EndDate;
            dbTeacher.Telephone    = teacher.Telephone;

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #5
0
        public IHttpActionResult PutClass(int id, Class @class)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != @class.ClassId)
            {
                return(BadRequest());
            }

            var dbClass = db.Classes.Find(id);

            dbClass.Name      = @class.Name;
            dbClass.TeacherId = @class.TeacherId;
            dbClass.StartDate = @class.StartDate;
            dbClass.EndDate   = @class.EndDate;


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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PutStudent(int id, Student student)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            var dbStudent = db.Students.Find(id);

            dbStudent.FirstName    = student.FirstName;
            dbStudent.LastName     = student.LastName;
            dbStudent.EmailAddress = student.EmailAddress;
            dbStudent.Telephone    = student.Telephone;

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }