Example #1
0
        public static void GetCourseById(int id, string sessionKey, Action <CourseModel> callback)
        {
            BackgroundWorker bw = new BackgroundWorker();

            bw.DoWork += ((se, ea) =>
            {
                var courseByIdResponse =
                    HttpRequester.Get <CourseModel>(BaseServicesUrl + "courses/" + id + "?sessionKey=" + sessionKey);
                ea.Result = courseByIdResponse;
            });
            bw.RunWorkerAsync();
            bw.RunWorkerCompleted += ((se, ea) =>
            {
                var result = ea.Result as CourseModel;
                if (callback != null)
                {
                    callback(result);
                }
            });
        }
Example #2
0
        public static void Search(string qeryString, string authenticationCode, Action <SearchResultModel> callback)
        {
            AppCache.Config.IsBusyPool.Add("Searching, please wait");
            var bw = new BackgroundWorker();

            bw.DoWork += ((se, ea) =>
            {
                var searchResponse = HttpRequester.Get <SearchResultModel>(BaseServicesUrl + "search?q=" + qeryString);
                ea.Result = searchResponse;
            });
            bw.RunWorkerAsync();
            bw.RunWorkerCompleted += ((se, ea) =>
            {
                AppCache.Config.IsBusyPool.TryRemove("Searching, please wait");
                var result = ea.Result as SearchResultModel;
                if (callback != null)
                {
                    callback(result);
                }
            });
        }
Example #3
0
        public static void LoadAllCourses(Action <IEnumerable <GlanceCourseModel> > callBack)
        {
            BackgroundWorker backgroundWorker = new BackgroundWorker();

            backgroundWorker.DoWork += ((se, ea) =>
            {
                var loginResponse = HttpRequester.Get <IEnumerable <GlanceCourseModel> >(BaseServicesUrl + "Courses");
                ea.Result = loginResponse;
            });

            backgroundWorker.RunWorkerCompleted += ((se, ea) =>
            {
                var result = ea.Result as IEnumerable <GlanceCourseModel>;
                if (callBack != null)
                {
                    callBack(result);
                }
            });

            backgroundWorker.RunWorkerAsync();
        }
Example #4
0
        //public static void Edit(string username, string nickname, UserType userType,
        //    string website, Gender gender, string hometown, DateTime? birthday,
        //    string email, string occupation, string aboutme, int studentNumber, DateTime registerDate,
        //    DateTime lastVisit, IEnumerable<CourseUserModel> courses, Action<LoginResponseModel> callback)
        //{
        //    //Username, Nickname, UserType, Website, Gender,Hometown,
        //    //        Birthday, Email, Occupation, Aboutme, StudentNumber, RegistrationDate,
        //    //        LastVisit, Courses


        //    AppCache.Config.IsBusyPool.Add("Editing, please wait");
        //    BackgroundWorker bw = new BackgroundWorker();
        //    bw.DoWork += ((se, ea) =>
        //    {
        //        //Validation!!!!!
        //        //validate username
        //        //validate email
        //        //validate authentication code
        //        //use validation from WebAPI
        //        var userFullModel = new UserFullModel()
        //        {
        //            Username = username,
        //            Nickname = nickname,
        //            UserType = userType,
        //            WebSite=website,
        //            Gender=gender,
        //            Hometown=hometown,
        //            Birthday=birthday,
        //            Email=email,
        //            Occupation=occupation,
        //            AboutMe=aboutme,
        //            StudentNumber=studentNumber,
        //            RegistrationDate=registerDate,
        //            LastVisit=lastVisit,
        //            Courses=courses,
        //        };
        //        var loginResponse = HttpRequester.Get<UserFullModel>(BaseServicesUrl + "users/register", userFullModel);
        //        ea.Result = loginResponse;
        //    });
        //    bw.RunWorkerAsync();
        //    bw.RunWorkerCompleted += ((se, ea) =>
        //    {
        //        AppCache.Config.IsBusyPool.TryRemove("Registering, please wait");
        //        var result = ea.Result as LoginResponseModel;
        //        if (callback != null)
        //        {
        //            callback(result);
        //        }
        //    });
        //}

        public static void PrintProfile(string username, string accessToken, Action <UserFullModel> callback)
        {
            AppCache.Config.IsBusyPool.Add("Loading user profile, please wait");
            var bw = new BackgroundWorker();

            bw.DoWork += ((se, ea) =>
            {
                var searchResponse = HttpRequester.Get <UserFullModel>(BaseServicesUrl + "/users/GetUser/" + username + "/?sessionKey=" + accessToken);
                // // api/users/get/{id}
                ea.Result = searchResponse;
            });
            bw.RunWorkerAsync();
            bw.RunWorkerCompleted += ((se, ea) =>
            {
                AppCache.Config.IsBusyPool.TryRemove("Loading user profile, please wait");
                var result = ea.Result as UserFullModel;
                if (callback != null)
                {
                    callback(result);
                }
            });
        }