Exemple #1
0
 public HttpResponseMessage TrainerSignUp([FromBody] Trainer model)
 {
     try
     {
         db.Trainers.Add(model);
         db.SaveChanges();
         return(Request.CreateResponse(HttpStatusCode.OK, model));
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
 public HttpResponseMessage PostStudent([FromBody] Student model)
 {
     try
     {
         db.Students.Add(model);
         db.SaveChanges();
         return(Request.CreateResponse(HttpStatusCode.OK, model));
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
Exemple #3
0
        public HttpResponseMessage Put(int id, [FromBody] Trainer trainer)
        {
            try
            {
                using (LearnTodayWebAPIDbEntities dbContext = new LearnTodayWebAPIDbEntities())
                {
                    var entity = dbContext.Trainers.FirstOrDefault(s => s.TrainerId == id);
                    if (entity == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Trainer with Id" + id.ToString() + " not found to updaate"));
                    }
                    else
                    {
                        entity.Password = trainer.Password;

                        dbContext.SaveChanges();
                        return(Request.CreateResponse(HttpStatusCode.OK, entity));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Exemple #4
0
 public HttpResponseMessage Post([FromBody] Trainer trainer)
 {
     try
     {
         using (LearnTodayWebAPIDbEntities dbContext = new LearnTodayWebAPIDbEntities())
         {
             dbContext.Trainers.Add(trainer);
             dbContext.SaveChanges();
             var message = Request.CreateResponse(HttpStatusCode.Created, trainer);
             return(message);
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
 public HttpResponseMessage Post([FromBody] Student model)
 {
     try
     {
         using (LearnTodayWebAPIDbEntities db = new LearnTodayWebAPIDbEntities())
         {
             db.Students.Add(model);
             db.SaveChanges();
             var message = Request.CreateResponse(HttpStatusCode.Created, model);
             return(message);
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
 public HttpResponseMessage Delete(int id)
 {
     try
     {
         using (LearnTodayWebAPIDbEntities db = new LearnTodayWebAPIDbEntities())
         {
             var entity = db.Students.FirstOrDefault(s => s.EnrollmentId == id);
             if (entity == null)
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "No enrollement information found"));
             }
             else
             {
                 db.Students.Remove(entity);
                 db.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.OK));
             }
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }