Esempio n. 1
0
        public bool SyncSystemData()
        {
            bool         flag           = false;
            string       schoolId       = ConfigurationManager.AppSettings["schoolId"];
            string       GradeUrl       = ConfigurationManager.AppSettings["GradeUrl"];
            string       ClassUrl       = ConfigurationManager.AppSettings["ClassUrl"];
            string       StudentIdsUrl  = ConfigurationManager.AppSettings["StudentIdsUrl"];
            string       StudentInfoUrl = ConfigurationManager.AppSettings["StudentsInfoUrl"];
            string       TermUrl        = ConfigurationManager.AppSettings["TermInfoUrl"];
            string       key            = ConfigurationManager.AppSettings["key"];
            string       registerAppId  = ConfigurationManager.AppSettings["requestAppId"];
            List <Grade> grades         = new List <Grade>();
            List <Class> classes        = new List <Class>();
            string       s = "";
            IDictionary <string, string> pairs = new Dictionary <string, string>
            {
                { "schoolId", schoolId }
            };
            string hmac             = commonUtill.GetHmac(pairs, key);
            string garderesult      = PostRequestClient(GradeUrl, "{ \"data\":{ \"schoolId\":\"" + schoolId + "\"}}");
            string classresult      = PostRequestClient(ClassUrl, "{ \"data\":{ \"schoolId\":\"" + schoolId + "\"}}");
            string studentIdsresult = PostRequestClient(StudentIdsUrl, "{\"data\":{\"schoolId\":\"" + schoolId + "\",\"hmac\":\"" + hmac + "\",\"registerAppId\":\"" + registerAppId + "\" } }");
            string termresult       = GetRequestClient(TermUrl + "?schoolId=" + schoolId);

            try
            {
                grades  = JsonUtill.JsonToJArray(garderesult);
                classes = JsonUtill.ClassJsonToJArray(classresult);
                s       = JsonUtill.StudentIdsJsonToJArray(studentIdsresult);
                Term               term = JsonUtill.TermJsonParse(termresult);
                string             studentInforesult = PostRequestClient(StudentInfoUrl, "{\"data\":{\"ids\":" + s + "}}");
                List <StudentInfo> studentInfos      = JsonUtill.StudentInfoJsonParse(studentInforesult);
                dbUtill.UpdateTerm(term);
                dbUtill.UpdateGrade(grades);
                dbUtill.UpdateClass(classes);
                dbUtill.InsertStudentInfo(studentInfos);
                flag = true;
            }
            catch (Exception)
            {
            }
            return(flag);
        }