//// GET api/<controller> //public IEnumerable<string> Get() //{ // return new string[] { "value1", "value2" }; //} // GET api/<controller>/5 public Lesson Get(int id) { Lesson lesson = LessonDal.Lessons.SingleOrDefault(l => l.Id == id); if (lesson == null) { throw ApiException.CreateException(HttpStatusCode.NotFound, string.Format("Course {0} not found", id), string.Format("Course {0} not found", id)); } return(lesson); }
// GET api/<controller>/5 public Topic Get(int id) { Topic topic = TopicDal.Topics.SingleOrDefault(t => t.Id == id); if (topic == null) { throw ApiException.CreateException(HttpStatusCode.NotFound, string.Format("Topic {0} not found", id), string.Format("Topic {0} not found", id)); } return(topic); }
// GET <controller>/5 public Course Get(int id) { var course = CourseDal.Courses.Single(c => c.Id == id); if (course == null) { throw ApiException.CreateException(HttpStatusCode.NotFound, string.Format("Course {0} not found", id), string.Format("Course {0} not found", id)); } return(course); }
public double Get(int id, int userId) { var subscription = SubscriptionDal.Subscriptions.SingleOrDefault(s => s.CourseId == id && s.UserId.Equals(userId)); if (subscription == null) { throw ApiException.CreateException(HttpStatusCode.BadRequest, "User is not enrolled.", "You must enroll in course"); } return(subscription.Rate); }
public IEnumerable <Course> List() { if (Request.RequestUri.ParseQueryString().Get("pagenumber") == string.Empty) { throw ApiException.CreateException(HttpStatusCode.BadRequest, "PageNumber is empty", "You must enter a value for the pagenumber, or not send this parameter"); } string language = Request.RequestUri.ParseQueryString().Get("lang") ?? DefaultValues["language"].ToString(); string sort = Request.RequestUri.ParseQueryString().Get("sort") ?? DefaultValues["sort"].ToString(); int pageNumber = Request.RequestUri.ParseQueryString().Get("pagenumber") == null ? (int)DefaultValues["pageNumber"] : Convert.ToInt32(Request.RequestUri.ParseQueryString().Get("pagenumber")); int pageSize = Request.RequestUri.ParseQueryString().Get("pagesize") == null ? (int)DefaultValues["pageSize"] : Convert.ToInt32(Request.RequestUri.ParseQueryString().Get("pagesize")); return(new DataAccess.CourseDal().List(language, pageNumber, pageSize, sort).ToArray()); }
// GET course/5/<controller> public IEnumerable <Author> Get(int courseId) { var course = CourseDal.Courses.SingleOrDefault(c => c.Id == courseId); if (course == null) { throw ApiException.CreateException(HttpStatusCode.NotFound, string.Format("Course {0} not found", courseId), "You must send a valid courseId."); } if (course.Authors == null) { throw ApiException.CreateException(HttpStatusCode.NotFound, string.Format("Course {0} has no authors", courseId), string.Format("Course {0} has no authors", courseId)); } return(course.Authors); }