Exemple #1
0
        public static bool syncStudent(int usertype = 0)
        {
            Propertise gbl          = new Propertise();
            string     ServerPortNo = string.Empty;
            var        Client       = new HttpClient();
            int        _UserID      = 0;

            try
            {
                var login = App.Database.GetLogInAsync();
                if (login != null)
                {
                    _UserID = login.Result.Code;
                }
                if (_UserID == 0 || usertype == 0)
                {
                    return(false);
                }
                //call student bind class and set data
                StudentAttendanceRequest studentRequest = new StudentAttendanceRequest()
                {
                    UserID     = _UserID,
                    UserType   = usertype,
                    DateString = gbl.ConsoleDateTimeFormat(Propertise.todayDate())
                };
                StudentAcknowledgementRequest studentAcknowledgementRequest = new StudentAcknowledgementRequest();

                GeneralProperties.ServicesMethodName = ServiceAPIInfo.download_StudentMetadata;
                string url = ServiceAPIInfo.serviceAPI + GeneralProperties.ServicesMethodName;
                Client.BaseAddress = new Uri(url);
                Client.Timeout     = TimeSpan.FromMilliseconds(ServiceAPIInfo.service_TimeOut);

                var json        = JsonConvert.SerializeObject(studentRequest, Formatting.Indented);
                var contentjson = new StringContent(json, Encoding.UTF8, ServiceAPIInfo.ContentMediaType);
                HttpResponseMessage responseAPI = Client.PostAsync(url, contentjson).Result;
                if (responseAPI.IsSuccessStatusCode == true)
                {
                    var test              = responseAPI.Content.ReadAsStringAsync();
                    var stringmsg         = (object)test.Result;
                    var download_Response = JsonConvert.DeserializeObject <StudentAttendanceResponse>(test.Result);
                    if (string.IsNullOrEmpty(download_Response.ToString()) || download_Response.Students.StudentAttendance.Count == 0)
                    {
                        return(false);
                    }
                    else
                    {
                        int status = App.Database.syncAttandanceData(download_Response).Result;
                        if (status > 0)
                        {
                            //after save data send student data in server
                            studentAcknowledgementRequest.UserID   = _UserID;
                            studentAcknowledgementRequest.UserType = usertype;
                            IList <EAttendanceTransaction> transactions = new List <EAttendanceTransaction>();
                            if (download_Response.Students.StudentAttendance.Count > 0)
                            {
                                for (int i = 0; i < download_Response.Students.StudentAttendance.Count; i++)
                                {
                                    int transactiontableCount = download_Response.Students.StudentAttendance[i].AttendanceTransaction.Count;
                                    for (int j = 0; j < transactiontableCount; j++)
                                    {
                                        EAttendanceTransaction transaction = new EAttendanceTransaction();
                                        transaction.Code = download_Response.Students.StudentAttendance[i].AttendanceTransaction[j].Code;
                                        transaction.AttendanceMaster_Code = download_Response.Students.StudentAttendance[i].AttendanceTransaction[j].AttendanceMaster_Code;
                                        transaction.FacultyMaster_Code    = download_Response.Students.StudentAttendance[i].AttendanceTransaction[j].FacultyMaster_Code;
                                        transaction.StudentMaster_Code    = download_Response.Students.StudentAttendance[i].AttendanceTransaction[j].StudentMaster_Code;
                                        transaction.StudentName           = download_Response.Students.StudentAttendance[i].AttendanceTransaction[j].StudentName;
                                        transaction.Status = download_Response.Students.StudentAttendance[i].AttendanceTransaction[j].Status;
                                        transactions.Add(transaction);
                                    }
                                }
                                studentAcknowledgementRequest.Transactions = transactions;
                            }

                            //here we again call for acknowledgement
                            GeneralProperties.ServicesMethodName = ServiceAPIInfo.request_Studentid;
                            url = ServiceAPIInfo.serviceAPI + GeneralProperties.ServicesMethodName;
                            Client.BaseAddress = new Uri(url);
                            Client.Timeout     = TimeSpan.FromMilliseconds(ServiceAPIInfo.service_TimeOut);

                            json        = JsonConvert.SerializeObject(studentAcknowledgementRequest, Formatting.Indented);
                            contentjson = new StringContent(json, Encoding.UTF8, ServiceAPIInfo.ContentMediaType);
                            responseAPI = Client.PostAsync(url, contentjson).Result;
                            if (responseAPI.IsSuccessStatusCode == true)
                            {
                                test      = responseAPI.Content.ReadAsStringAsync();
                                stringmsg = (object)test.Result;
                                if (!string.IsNullOrEmpty(stringmsg.ToString()))
                                {
                                    Console.WriteLine("Successfull download student data !");
                                    return(true);
                                }
                                else
                                {
                                    Console.WriteLine("Fail on the Acknowledge request !");
                                    return(false);
                                }
                            }
                        }
                    }
                }
                else
                {
                    Console.Write(responseAPI.RequestMessage);
                }
            }
            catch (WebException Ex)
            {
                Console.WriteLine(Ex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(false);
        }
Exemple #2
0
        //Bind Data In Server
        /// <summary>
        /// Gets the metadata service.
        /// we are se S for student and M for Metadata
        /// </summary>
        /// <returns><c>true</c>, if metadata service was gotten, <c>false</c> otherwise.</returns>
        /// <param name="MetaDataType">Meta data type.</param>
        public bool GetMetadataService(char MetaDataType)
        {
            bool check_ServiceStatus = false;
            var  Client = new HttpClient();

            try
            {
                if (MetaDataType == 'M')
                {
                    if (UserType.currentUserType == UserType.enumUserType.Faculty)
                    {
                        ServiceAPIInfo.MetaDataMethod = "DownloadFacultyMetadata";
                    }
                    else if (UserType.currentUserType == UserType.enumUserType.Student)
                    {
                        ServiceAPIInfo.MetaDataMethod = "DownloadStudentMetadata";
                    }
                    else if (UserType.currentUserType == UserType.enumUserType.Parent)
                    {
                        ServiceAPIInfo.MetaDataMethod = "DownloadParentMetadata";
                    }
                    else if (UserType.currentUserType == UserType.enumUserType.Management)
                    {
                        ServiceAPIInfo.MetaDataMethod = "DownloadManagementMetadata";
                    }
                }
                else if (MetaDataType == 'S')
                {
                    ServiceAPIInfo.MetaDataMethod = "GetStudentAllAttendence";
                }
                DownloadUserMetadataRequest cngRequest = new DownloadUserMetadataRequest();
                StudentAttendanceRequest    lgR        = new StudentAttendanceRequest();
                GeneralProperties.ServicesMethodName = ServiceAPIInfo.MetaDataMethod;

                string url = ServiceAPIInfo.serviceAPI + GeneralProperties.ServicesMethodName;
                //Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                Client.BaseAddress = new Uri(url);
                //Client.Timeout = TimeSpan.FromMilliseconds(ServiceAPIInfo.service_TimeOut);

                string json     = "";
                var    id       = CrossSettings.Current.GetValueOrDefault("FacultyId", 0);
                var    userType = CrossSettings.Current.GetValueOrDefault("UserType", 0);

                if (MetaDataType == 'M')
                {
                    cngRequest.UserID = id;
                    //cngRequest.UserID = 1;
                    cngRequest.UserType = userType;
                    /* Encode class data */
                    json = JsonConvert.SerializeObject(cngRequest, Formatting.Indented);
                }
                else if (MetaDataType == 'S')
                {
                    lgR.UserID     = id;
                    lgR.UserType   = userType;
                    lgR.DateString = "";
                    json           = JsonConvert.SerializeObject(lgR, Formatting.Indented);
                }

                var contentjson = new StringContent(json, Encoding.UTF8, ServiceAPIInfo.ContentMediaType);
                HttpResponseMessage responseAPI = Client.PostAsync(url, contentjson).Result;
                if (responseAPI.IsSuccessStatusCode == true)
                {
                    var test      = responseAPI.Content.ReadAsStringAsync();
                    var stringmsg = (object)test.Result;
                    if (MetaDataType == 'M')
                    {
                        if (UserType.currentUserType == UserType.enumUserType.Faculty)
                        {
                            download_FacultyMetadataResponse = JsonConvert.DeserializeObject <DownloadFacultyMetadataResponse>(test.Result);
                            MetaDataBind(download_FacultyMetadataResponse);
                        }
                        else if (UserType.currentUserType == UserType.enumUserType.Student)
                        {
                            download_StudentMetadaaResponse = JsonConvert.DeserializeObject <DownloadStudentMetadataResponse>(test.Result);
                            MetaDataBindForStudent(download_StudentMetadaaResponse);
                        }
                        else if (UserType.currentUserType == UserType.enumUserType.Parent)
                        {
                            download_ParentMetadataResponse = JsonConvert.DeserializeObject <DownloadParentMetadataResponse>(test.Result);
                            MetaDataBindForParent(download_ParentMetadataResponse);
                        }
                        else if (UserType.currentUserType == UserType.enumUserType.Management)
                        {
                            //here we are defind for management
                        }
                    }
                    else if (MetaDataType == 'S')
                    {
                        responseStudentAttendance = JsonConvert.DeserializeObject <StudentAttendanceResponse>(test.Result);
                        StudentDataBind(responseStudentAttendance);
                    }
                    var result = JsonConvert.DeserializeObject <LogInResponse>(test.Result);
                    if (!string.IsNullOrWhiteSpace(result.ToString()))
                    {
                        check_ServiceStatus = true;
                    }
                }
                else
                {
                    StrMSG = ErrorMsg("Server is not responding..");
                    check_ServiceStatus = false;
                }
            }
            catch (WebException ex)
            {
                StrMSG = ErrorMsg(ex.ToString());
                check_ServiceStatus = false;
            }
            catch (ProtocolViolationException ex)
            {
                StrMSG = ErrorMsg(ex.ToString());
                check_ServiceStatus = false;
            }
            catch (AggregateException ex)
            {
                StrMSG = ErrorMsg("Server is not responding..");
                Console.WriteLine(ex.InnerException.Message);
                check_ServiceStatus = false;
            }
            catch (Exception ex)
            {
                StrMSG = ErrorMsg("Error on Downloading..");
                Console.WriteLine(ex.InnerException.Message);
                check_ServiceStatus = false;
            }
            return(check_ServiceStatus);
        }