public HttpResponseMessage GetAllCourses() { LearnTodayWenAPIContext context = new LearnTodayWenAPIContext(); var list = (from c in context.Courses select new { CourseId = c.CourseId, Title = c.Title, Fees = c.Fees, Description = c.Description, Trainer = c.Trainer, Start_Date = c.Start_Date }).ToList(); return(Request.CreateResponse(HttpStatusCode.OK, list)); }
public HttpResponseMessage TrainerSignUp([FromBody] Trainer model) { try { LearnTodayWenAPIContext con = new LearnTodayWenAPIContext(); con.Trainers.Add(model); con.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Created, model)); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.BadRequest, e)); } }
public HttpResponseMessage PostStudent([FromBody] Student model) { try { using (LearnTodayWenAPIContext context = new LearnTodayWenAPIContext()) { context.Students.Add(model); context.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Created, model)); } } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.BadRequest, e)); } }
public HttpResponseMessage UpdatePassword(int id, [FromBody] Trainer model) { try { LearnTodayWenAPIContext c = new LearnTodayWenAPIContext(); Trainer t = c.Trainers.FirstOrDefault(x => x.TrainerId == id); if (t != null) { t.Password = model.Password; c.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, "Data Updated Successfully")); } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "Searched Data not Found")); } } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.BadRequest, e)); } }
public HttpResponseMessage GetCourseById(int id) { try { using (LearnTodayWenAPIContext context = new LearnTodayWenAPIContext()) { Course c = context.Courses.Where(x => x.CourseId == id).SingleOrDefault(); if (c != null) { var op = new { CourseId = c.CourseId, Title = c.Title, Fees = c.Fees, Description = c.Description, Trainer = c.Trainer, Start_Date = c.Start_Date }; return(Request.CreateResponse(HttpStatusCode.OK, op)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "Searched Data not Found")); } } } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.BadRequest, e)); } }
public HttpResponseMessage DeleteStudentEnrollment(int id) { try { using (LearnTodayWenAPIContext co = new LearnTodayWenAPIContext()) { var s = co.Students.FirstOrDefault(x => x.EnrollementId == id); if (s != null) { co.Students.Remove(s); co.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, "Deleted successfully")); } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "No Enrollement information found")); } } } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.BadRequest, e)); } }