SchooxSharp.Api.Clients.Dashboard.GetCourses C# (CSharp) Method

GetCourses() public method

Returns a list of all courses with title, short description and image. NOTE: NOT ALL PROPERTIES ARE RETURNED WITH THIS RESPONSE.
public GetCourses ( string role ) : SchooxResponse>
role string User's role.
return SchooxResponse>
        public SchooxResponse<List<Course>> GetCourses(string role)
        {
            if(string.IsNullOrWhiteSpace(role))
                throw new ArgumentNullException("role");

            //GET /dashboard/courses
            var request = SService.GenerateBaseRequest("/dashboard/courses");
            request.Method = Method.GET;

            request.AddNonBlankQueryString ("role", role);

            return Execute<List<Course>>(request);
        }

Usage Example

コード例 #1
0
ファイル: Program.cs プロジェクト: jamesbar2/SchooxSharp
        static void Main(string[] args)
        {
            //note the App.config file that has the values for auto loading the configuration
            var schooxService = new SchooxService();

            var dashboard = new Dashboard(schooxService);
            var courses = new Courses(schooxService);

            //lets get the courses
            var coursesResponse = dashboard.GetCourses(Roles.SchooxInternalEmployee);

            if (coursesResponse.RequestSuccessful && coursesResponse.Data != null)
            {
                Console.WriteLine("Request from\n{0}\n{1} courses returned:", coursesResponse.Response.ResponseUri,
                    coursesResponse.Data.Count);

                foreach (var course in coursesResponse.Data)
                {
                    Console.WriteLine("#{0} - {1} - # of Students: {2}", course.Id, course.Title, course.Students);
                }

                //now that we have the courses, let's pull details for the first one
                var firstCourse = coursesResponse.Data.FirstOrDefault();

                if (firstCourse != null)
                {
                    var courseDetail = courses.GetDetailsForCourse(firstCourse.Id);
                    Console.WriteLine("\nDetails for Course:\n{0}", courseDetail.Data);
                }
            }
            else
            {
                Console.WriteLine("No courses found or data null for \"{0}\" courses, check the URL\n{1}.", Roles.SchooxInternalEmployee,
                    coursesResponse.Response.ResponseUri);
            }

            Console.Read();
        }