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

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

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

            student.Id = newStudent.StudentIdentification;
            return Ok(student);
        }
        public IHttpActionResult Create(StudentModel student)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var newStudent = new Student
            {
                FirstName = student.FirstName,
                LastName = student.LastName,
                Level = student.Level,
                Assistant = student.Assistant,
                AdditionalInformation = student.AdditionalInformation
            };

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

            student.StudentIdentification = newStudent.StudentIdentification;

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

            var existingStudent = this.data
                .Students
                .All()
                .FirstOrDefault(s => s.StudentIdentification == id);

            if (existingStudent == null)
            {
                return this.BadRequest("No such student found!");
            }

            existingStudent.FirstName = student.FirstName;
            existingStudent.LastName = student.LastName;
            this.data.SaveChanges();

            student.Id = existingStudent.StudentIdentification;
            return this.Ok(student);
        }