Пример #1
0
        public HttpResponseMessage Delete(int id)
        {
            try
            {
                using (dbtutorsEntities entities = new dbtutorsEntities())
                {
                    var entity = entities.tbl_students.Remove(entities.tbl_students.FirstOrDefault(t => t.ID == id));


                    if (entity == null)
                    {
                        return(Request.CreateResponse(HttpStatusCode.NotFound, "Tutor with ID=" + id.ToString() + "not found to be deleted"));
                    }
                    else
                    {
                        entities.tbl_students.Remove(entity);
                        entities.SaveChanges();
                        return(Request.CreateResponse(HttpStatusCode.OK));
                    }
                }
            }
            catch (Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e));
            }
        }
Пример #2
0
        public HttpResponseMessage Put(int id, [FromBody] tbl_students tutor)
        {
            try
            {
                using (dbtutorsEntities entities = new dbtutorsEntities())
                {
                    var entity = entities.tbl_students.FirstOrDefault(t => t.ID == id);

                    if (entity == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Tutor with ID=" + id.ToString() + "not found to be updated"));
                    }


                    else
                    {
                        entity.ID        = tutor.ID;
                        entity.StdEmail  = tutor.StdEmail;
                        entity.StdFName  = tutor.StdFName;
                        entity.StdLName  = tutor.StdLName;
                        entity.StdGender = tutor.StdGender;
                        entity.Password  = tutor.Password;
                        entity.Confirm   = tutor.Confirm;

                        entities.SaveChanges();
                        return(Request.CreateResponse(HttpStatusCode.OK));
                    }
                }
            }

            catch (Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e));
            }
        }
Пример #3
0
 public HttpResponseMessage Post([FromBody] tbl_students tutor)
 {
     try
     {
         using (dbtutorsEntities entities = new dbtutorsEntities())
         {
             entities.tbl_students.Add(tutor);
             entities.SaveChanges();
             var message = Request.CreateResponse(HttpStatusCode.Created, tutor);
             message.Headers.Location = new Uri(Request.RequestUri + tutor.ID.ToString());
             return(message);
         }
     }
     catch (Exception e)
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest, e));
     }
 }