public static string CreateCourses(List <MoodleCourse> list, string token)
        {
            string postData = "?wstoken=" + token + "&wsfunction=core_course_create_courses";

            for (int i = 0; i < list.Count; i++)
            {
                postData += "&courses[" + i + "][fullname]=" + HttpUtility.UrlEncode(list[i].FullName);
                postData += "&courses[" + i + "][shortname]=" + HttpUtility.UrlEncode(list[i].ShortName);
                postData += "&courses[" + i + "][categoryid]=" + list[i].CategoryId;
                postData += "&courses[" + i + "][idnumber]=" + HttpUtility.UrlEncode(list[i].IdNumber);
                postData += "&courses[" + i + "][summary]=" + HttpUtility.UrlEncode(list[i].Summary);
                postData += "&courses[" + i + "][summaryformat]=" + list[i].SummaryFormat;
                postData += "&courses[" + i + "][format]=" + HttpUtility.UrlEncode(list[i].Format);
                postData += "&courses[" + i + "][showgrades]=" + list[i].ShowGrades;
                postData += "&courses[" + i + "][newsitems]=" + list[i].NewsItems;
                postData += "&courses[" + i + "][startdate]=" + list[i].StartDate;
                postData += "&courses[" + i + "][numsections]=" + list[i].NumSections;
                postData += "&courses[" + i + "][maxbytes]=" + list[i].MaxBytes;
                postData += "&courses[" + i + "][showreports]=" + list[i].ShowReports;
                postData += "&courses[" + i + "][visible]=" + list[i].Visible;
                postData += "&courses[" + i + "][hiddensections]=" + list[i].HiddenSections;
                postData += "&courses[" + i + "][groupmode]=" + list[i].GroupMode;
                postData += "&courses[" + i + "][groupmodeforce]=" + list[i].GroupModeForce;
                postData += "&courses[" + i + "][defaultgroupingid]=" + list[i].DefaultGroupingId;
                postData += "&courses[" + i + "][enablecompletion]=" + list[i].EnableCompletion;
                postData += "&courses[" + i + "][completionstartonenrol]=" + list[i].CompletionStartOnEnrol;
                postData += "&courses[" + i + "][completionnotify]=" + list[i].CompletionNotify;
                postData += "&courses[" + i + "][lang]=" + HttpUtility.UrlEncode(list[i].Lang);
                postData += "&courses[" + i + "][forcetheme]=" + HttpUtility.UrlEncode(list[i].ForceTheme);
            }

            MoodleWebRequest web = new MoodleWebRequest(MoodleUrl.RestUrl + postData);

            return(web.GetResponse());
        }
        public static string GetUsersCourses(int userId, string token)
        {
            string postData = "?wstoken=" + token + "&wsfunction=core_enrol_get_users_courses";

            postData += "&userid=" + userId;
            MoodleWebRequest web = new MoodleWebRequest(MoodleUrl.RestUrl + postData);

            return(web.GetResponse());
        }
        public static string GetCourseContents(int courseId, string token)
        {
            string postData = "?wstoken=" + token + "&wsfunction=core_course_get_contents";

            postData += "&courseid=" + courseId;

            MoodleWebRequest web = new MoodleWebRequest(MoodleUrl.RestUrl + postData);

            return(web.GetResponse());
        }
        public static string GetCourses(List <int> list, string token)
        {
            string postData = "?wstoken=" + token + "&wsfunction=core_course_get_courses";

            for (int i = 0; i < list.Count; i++)
            {
                postData += "&options[ids][" + i + "]=" + list[i];
            }

            MoodleWebRequest web = new MoodleWebRequest(MoodleUrl.RestUrl + postData);

            return(web.GetResponse());
        }
Exemple #5
0
        public static string GetGroups(List <int> lst, string token)
        {
            string postData = "?wstoken=" + token + "&wsfunction=core_group_get_groups";

            for (int i = 0; i < lst.Count; i++)
            {
                postData += "&groupids[" + i + "]=" + lst[i];
            }

            MoodleWebRequest web = new MoodleWebRequest(MoodleUrl.RestUrl + postData);

            return(web.GetResponse());
        }
        public static string GetUsersById(List <int> list, string token)
        {
            string postData = "?wstoken=" + token + "&wsfunction=core_user_get_users_by_id";

            //Duyệt các người dùng trong danh sách lấy id
            for (int i = 0; i < list.Count; i++)
            {
                postData += "&userids[" + i + "]=" + list[i];
            }

            MoodleWebRequest web = new MoodleWebRequest(MoodleUrl.RestUrl + postData);

            return(web.GetResponse());
        }
Exemple #7
0
        public static string UnassignGrouping(List <KeyValuePair <int, int> > list, string token)
        {
            string postData = "?wstoken=" + token + "&wsfunction=core_group_unassign_grouping";

            for (int i = 0; i < list.Count; i++)
            {
                postData += "&unassignments[" + i + "][groupingid]=" + list[i].Key;
                postData += "&unassignments[" + i + "][groupid]=" + list[i].Value;
            }

            MoodleWebRequest web = new MoodleWebRequest(MoodleUrl.RestUrl + postData);

            return(web.GetResponse());
        }
Exemple #8
0
        public static string DeleteGroupMembers(List <KeyValuePair <int, int> > list, string token)
        {
            string postData = "?wstoken=" + token + "&wsfunction=core_group_delete_group_members";

            for (int i = 0; i < list.Count; i++)
            {
                postData += "&members[" + i + "][groupid]=" + list[i].Key;
                postData += "&members[" + i + "][userid]=" + list[i].Value;
            }

            MoodleWebRequest web = new MoodleWebRequest(MoodleUrl.RestUrl + postData);

            return(web.GetResponse());
        }
Exemple #9
0
        public static string UnassignRoles(List <MoodleRole> lst, string token)
        {
            string postData = "?wstoken=" + token + "&wsfunction=core_role_unassign_roles";

            for (int i = 0; i < lst.Count; i++)
            {
                postData += "&unassignments[" + i + "][roleid]=" + lst[i].RoleId;
                postData += "&unassignments[" + i + "][userid]=" + lst[i].UserId;
                postData += "&unassignments[" + i + "][contextid]=" + lst[i].ContextId;
            }

            MoodleWebRequest web = new MoodleWebRequest(MoodleUrl.RestUrl + postData);

            return(web.GetResponse());
        }
        public static string GetUsersByCourseId(List <KeyValuePair <int, int> > list, string token)
        {
            string postData = "?wstoken=" + token + "&wsfunction=core_user_get_course_user_profiles";

            //Duyệt các người dùng trong danh sách lấy id
            for (int i = 0; i < list.Count; i++)
            {
                postData += "&userlist[" + i + "][userid]=" + list[i].Key;
                postData += "&userlist[" + i + "][courseid]=" + list[i].Value;
            }

            MoodleWebRequest web = new MoodleWebRequest(MoodleUrl.RestUrl + postData);

            return(web.GetResponse());
        }
Exemple #11
0
        public static string CreateGroupings(List <MoodleGroup> list, string token)
        {
            string postData = "?wstoken=" + token + "&wsfunction=core_group_create_groupings";

            for (int i = 0; i < list.Count; i++)
            {
                postData += "&groupings[" + i + "][courseid]=" + list[i].CourseId;
                postData += "&groupings[" + i + "][name]=" + HttpUtility.UrlEncode(list[i].Name);
                postData += "&groupings[" + i + "][description]=" + HttpUtility.UrlEncode(list[i].Description);
                postData += "&groupings[" + i + "][descriptionformat]=" + list[i].DescriptionFormat;
            }

            MoodleWebRequest web = new MoodleWebRequest(MoodleUrl.RestUrl + postData);

            return(web.GetResponse());
        }
        public static string GetEnrolledUsers(int courseId, List <KeyValuePair <string, string> > options, string token)
        {
            string postData = "?wstoken=" + token + "&wsfunction=core_enrol_get_enrolled_users";

            postData += "&courseid=" + courseId;

            for (int i = 0; i < options.Count; i++)
            {
                postData += "&options[" + i + "][name]=" + options[i].Key;
                postData += "&options[" + i + "][value]=" + options[i].Value;
            }

            MoodleWebRequest web = new MoodleWebRequest(MoodleUrl.RestUrl + postData);

            return(web.GetResponse());
        }
        public static string SendInstantMessages(List <MoodleMessage> list, string token)
        {
            string postData = "?wstoken=" + token + "&wsfunction=core_message_send_instant_messages";

            for (int i = 0; i < list.Count; i++)
            {
                postData += "&messages[" + i + "][touserid]=" + list[i].ToUserId;
                postData += "&messages[" + i + "][text]=" + HttpUtility.UrlEncode(list[i].Text);
                postData += "&messages[" + i + "][textformat]=" + list[i].TextFormat;
                postData += "&messages[" + i + "][clientmsgid]=" + list[i].ClientMsgId;
            }

            MoodleWebRequest web = new MoodleWebRequest(MoodleUrl.RestUrl + postData);

            return(web.GetResponse());
        }
        public static string DeleteCategories(List <MoodleDeleteCategory> lstDeleteCategory, string token)
        {
            string postData = "wstoken=" + token + "&wsfunction=core_course_delete_categories";

            //Duyệt các Category trong danh sách lấy thông tin cập nhật
            for (int i = 0; i < lstDeleteCategory.Count; i++)
            {
                postData += "&categories[" + i + "][id]=" + lstDeleteCategory[i].Id;
                postData += "&categories[" + i + "][newparent]=" + lstDeleteCategory[i].NewParent;
                postData += "&categories[" + i + "][recursive]=" + lstDeleteCategory[i].Recursive;
            }

            MoodleWebRequest web = new MoodleWebRequest(MoodleUrl.RestUrl, "POST", postData);

            return(web.GetResponse());
        }
        public string GetToken(string service)
        {
            MoodleWebRequest web = new MoodleWebRequest(MoodleUrl.LoginUrl, "POST", "username="******"&password="******"&service=" + service);

            // Chuỗi có dạng {"token":"d75f2169ec6320a689c67fb5869360e1"}
            string s = web.GetResponse();

            string[] rs = s.Split(new char[] { '"' });
            MoodleUtilites.WriteTextToFile("D:\\token.txt", s);
            // Sau khi tách s[5] = {"","token",":","d75f2169ec6320a689c67fb5869360e1",""}
            if (rs.Count() != 5)
            {
                return("");
            }

            return(rs[3].Trim());
        }
        public static string GetCategories(List <KeyValuePair <string, string> > list, bool addSubCategories, string token)
        {
            string postData = "wstoken=" + token + "&wsfunction=core_course_get_categories";

            //Duyệt các Category trong danh sách lấy thông tin cập nhật
            for (int i = 0; i < list.Count; i++)
            {
                postData += "&criteria[" + i + "][key]=" + list[i].Key;
                postData += "&criteria[" + i + "][value]=" + HttpUtility.UrlEncode(list[i].Value);
            }

            if (addSubCategories == false)
            {
                postData += "&addsubcategories=0";
            }
            MoodleWebRequest web = new MoodleWebRequest(MoodleUrl.RestUrl, "POST", postData);

            return(web.GetResponse());
        }
        public static string UpdateCategories(List <MoodleCategory> lstCategory, string token)
        {
            string postData = "wstoken=" + token + "&wsfunction=core_course_update_categories";

            //Duyệt các Category trong danh sách lấy thông tin cập nhật
            for (int i = 0; i < lstCategory.Count; i++)
            {
                postData += "&categories[" + i + "][id]=" + lstCategory[i].Id;
                postData += "&categories[" + i + "][name]=" + HttpUtility.UrlEncode(lstCategory[i].Name);
                postData += "&categories[" + i + "][parent]=" + lstCategory[i].Parent;
                postData += "&categories[" + i + "][idnumber]=" + HttpUtility.UrlEncode(lstCategory[i].IdNumber);
                postData += "&categories[" + i + "][description]=" + HttpUtility.UrlEncode(lstCategory[i].Description);
                postData += "&categories[" + i + "][descriptionformat]=" + lstCategory[i].DescriptionFormat;
                postData += "&categories[" + i + "][theme]=" + lstCategory[i].Theme;
            }

            MoodleWebRequest web = new MoodleWebRequest(MoodleUrl.RestUrl, "POST", postData);

            return(web.GetResponse());
        }
        public static string EnrolUsers(List <MoodleEnrol> lst, string token)
        {
            string postData = "?wstoken=" + token + "&wsfunction=enrol_manual_enrol_users";

            for (int i = 0; i < lst.Count; i++)
            {
                postData += "&enrolments[" + i + "][roleid]=" + lst[i].RoleId;
                postData += "&enrolments[" + i + "][userid]=" + lst[i].UserId;
                postData += "&enrolments[" + i + "][courseid]=" + lst[i].CourseId;
                postData += "&enrolments[" + i + "][timestart]=" + lst[i].TimeStart;
                postData += "&enrolments[" + i + "][timeend]=" + lst[i].TimeEnd;
                postData += "&enrolments[" + i + "][suspend]=" + lst[i].Suspend;
            }

            MoodleWebRequest web = new MoodleWebRequest(MoodleUrl.RestUrl + postData);



            return(web.GetResponse());
        }
        public static string CreateUsers(List <MoodleUser> list, string token)
        {
            string postData = "wstoken=" + token + "&wsfunction=core_user_create_users";

            //Duyệt các người dùng trong danh sách lấy thông tin cần cho tạo người dùng
            for (int i = 0; i < list.Count; i++)
            {
                postData += "&users[" + i + "][username]=" + list[i].Username;
                postData += "&users[" + i + "][password]=" + list[i].Password;
                postData += "&users[" + i + "][firstname]=" + HttpUtility.UrlEncode(list[i].Firstname);
                postData += "&users[" + i + "][lastname]=" + HttpUtility.UrlEncode(list[i].Lastname);
                postData += "&users[" + i + "][email]=" + list[i].Email;
                postData += "&users[" + i + "][timezone]=" + HttpUtility.UrlEncode(list[i].Timezone);
                postData += "&users[" + i + "][city]=" + HttpUtility.UrlEncode(list[i].City);
                postData += "&users[" + i + "][country]=" + HttpUtility.UrlEncode(list[i].Country);
            }

            MoodleWebRequest web = new MoodleWebRequest(MoodleUrl.RestUrl, "POST", postData);

            return(web.GetResponse());
        }
        public static string UpdateUsers(List <MoodleUser> list, string token)
        {
            string postData = "?wstoken=" + token + "&wsfunction=core_user_update_users";

            //Duyệt các người dùng trong danh sách lấy thông tin cần cập nhật
            for (int i = 0; i < list.Count; i++)
            {
                postData += "&users[" + i + "][id]=" + list[i].Id;
                if (list[i].Username != "")
                {
                    postData += "&users[" + i + "][username]=" + list[i].Username;
                }

                if (list[i].Password != "")
                {
                    postData += "&users[" + i + "][password]=" + list[i].Password;
                }

                if (list[i].Firstname != "")
                {
                    postData += "&users[" + i + "][firstname]=" + HttpUtility.UrlEncode(list[i].Firstname);
                }

                if (list[i].Lastname != "")
                {
                    postData += "&users[" + i + "][lastname]=" + HttpUtility.UrlEncode(list[i].Lastname);
                }

                if (list[i].Email != "")
                {
                    postData += "&users[" + i + "][email]=" + list[i].Email;
                }
            }

            MoodleWebRequest web = new MoodleWebRequest(MoodleUrl.RestUrl + postData);

            return(web.GetResponse());
        }
Exemple #21
0
        public static string GetServiceXml(string token)
        {
            MoodleWebRequest web = new MoodleWebRequest(MoodleUrl.SoapUrl + "?wsdl=1&wstoken=" + token);

            return(web.GetResponse());
        }