Exemplo n.º 1
0
        //PUT or Update the data

        public IHttpActionResult PutCustomer(StudentDisplay student)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("This is invalid Model. Please recheck"));
            }

            using (var x = new WebAPI_PeopleEntities())
            {
                var checkExistingStudent = x.Students.Where(s => s.id == student.Id).FirstOrDefault <Student>();

                if (checkExistingStudent != null)
                {
                    checkExistingStudent.name    = student.Name;
                    checkExistingStudent.country = student.Country;
                    checkExistingStudent.phone   = student.Phone;
                    checkExistingStudent.tempadd = student.TempAdd;

                    x.SaveChanges();
                }
                else
                {
                    return(NotFound());
                }
            }

            return(Ok());
        }
Exemplo n.º 2
0
        //Delete a record in the database

        public IHttpActionResult Delete(int id)
        {
            if (id <= 0)
            {
                return(BadRequest("Please enter valid Customer Id"));
            }

            using (var x = new WebAPI_PeopleEntities())
            {
                var student = x.Students.Where(s => s.id == id).FirstOrDefault();

                x.Entry(student).State = System.Data.Entity.EntityState.Deleted;
                x.SaveChanges();
            }
            return(Ok());
        }
Exemplo n.º 3
0
        //Post The data
        public IHttpActionResult PostNewStudent(StudentDisplay student)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid Data. Please Recheck!"));
            }

            using (var x = new WebAPI_PeopleEntities())
            {
                x.Students.Add(new Student()
                {
                    name    = student.Name,
                    email   = student.Email,
                    country = student.Country,
                    phone   = student.Phone,
                    tempadd = student.TempAdd
                });

                x.SaveChanges();
            }
            return(Ok());
        }