Ejemplo n.º 1
0
        public IHttpActionResult Edit(StudentModel studentModel)
        {
            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            var student = this.StudentSystemData.Students.Find(studentModel.StudentId);
            if (student == null)
            {
                return this.NotFound();
            }

            try
            {
                student.Name = studentModel.Name;
                this.StudentSystemData.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!this.StudentExists(studentModel.StudentId))
                {
                    return this.NotFound();
                }
                else
                {
                    throw;
                }
            }

            return this.StatusCode(HttpStatusCode.NoContent);
        }
        public IHttpActionResult AddStudent(string courseName, StudentModel model)
        {

            var course = this.data.Courses.All().FirstOrDefault(x => x.Name == courseName);
            if (course == null)
            {
                return this.BadRequest("There is no such course!");
            }

            if (!ModelState.IsValid)
            {
                return this.BadRequest(ModelState);
            }

            var student = new Student()
                              {
                                  StudentIdentification = model.StudentIdentification,
                                  AdditionalInformation = model.AdditionalInformation,
                                  FirstName = model.FirstName,
                                  LastName = model.LastName,
                                  Level = model.Level
                              };
            
            course.Students.Add(student);
            this.data.SaveChanges();
            return this.Ok(CourseModel.TransformCourse(course));
        }
 public IHttpActionResult Create(StudentModel model)
 {
     if (!ModelState.IsValid)
     {
         return this.BadRequest(ModelState);
     }
     var student = new Student()
                       {
                           StudentIdentification = model.StudentIdentification,
                           AdditionalInformation = model.AdditionalInformation,
                           FirstName = model.FirstName,
                           LastName = model.LastName,
                           Level = model.Level
                       };
     this.data.Students.Add(student);
     this.data.SaveChanges();
     return this.Ok(StudentModel.TransformStudent(student));
 }
        public IHttpActionResult Add(StudentModel student)
        {
            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            var newStudent = new Student()
            {
                FirstName = student.FirstName,
                LastName = student.LastName,
                Level = student.Level
            };

            this.repository.InsertStudent(newStudent);
            this.repository.Save();

            return this.Ok(student);
        }
        public IHttpActionResult Create(StudentModel student)
        {
            if (!this.ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var newStudent = new Student
            {
                Name = student.Name,
                Number = student.Number
            };

            this.data.Students.Add(newStudent);
            this.data.SaveChanges();

            student.StudentId = newStudent.StudentId;

            return Ok(student);
        }
Ejemplo n.º 6
0
        public IHttpActionResult Create(StudentModel student)
        {
            if (!this.ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var newStudent = new Student()
            {
                FirstName = student.FirstName,
                LastName = student.LastName,
                Level = student.Level
            };

            this.data.Students.Add(newStudent);
            this.data.SaveChanges();

            student.StudentId = newStudent.StudentId;
            return Ok(student);
        }
        public IHttpActionResult Update(int id, StudentModel student)
        {
            if (!this.ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var existingStudent = this.data.Students.All().First(s => s.StudentId == id);

            if (existingStudent == null)
            {
                return BadRequest("Such student does not exist!");
            }

            existingStudent.Name = student.Name;
            existingStudent.Number = student.Number;
            this.data.SaveChanges();

            student.StudentId = id;

            return Ok(student);
        }
Ejemplo n.º 8
0
        public IHttpActionResult Update(int id, StudentModel student)
        {
            if (!this.ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var studentToUpdate = this.data.Students.All().FirstOrDefault(s => s.StudentId == id);

            if (studentToUpdate == null)
            {
                return BadRequest("Student with this id: " + id + " does not exists.");
            }

            studentToUpdate.FirstName = student.FirstName;
            studentToUpdate.LastName = student.LastName;
            studentToUpdate.Level = student.Level;
            this.data.SaveChanges();

            student.StudentId = id;
            return Ok(student);
        }
        public IHttpActionResult Update(int id, StudentModel student)
        {
            if (!this.ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var existingStudent = this.data.Students.All().FirstOrDefault(x => x.ID == id);

            if (existingStudent == null)
            {
                return BadRequest("Invalid Student");
            }

            // Check if some of the fields in the new data are not null
            existingStudent.FirstName = student.FirstName;
            existingStudent.LastName = student.LastName;
            existingStudent.Number = student.Number;
            this.data.Students.SaveChanges();

            student.ID = existingStudent.ID;
            return Ok(student);
        }