/// <summary> /// method declare for TimeTable sync /// </summary> /// <param name="Connection"></param> /// <returns></returns> public static async Task syncTimeTable(int _UserID, UserType.enumUserType _userType, bool _FromStudentData = true) { Propertise gbl = new Propertise(); string ServerPortNo = string.Empty; var Client = new HttpClient(); try { GeneralProperties.ServicesMethodName = ServiceAPIInfo.SyncTimeTable; string url = ServiceAPIInfo.serviceAPI + GeneralProperties.ServicesMethodName; Client.BaseAddress = new Uri(url); Client.Timeout = TimeSpan.FromMilliseconds(ServiceAPIInfo.service_TimeOut); //call student bind class and set data TimeTableRequest timetableRequest = new TimeTableRequest() { UserID = _UserID, UserType = (int)_userType, DateString = gbl.ConsoleDateTimeFormat(Propertise.todayDate()), CheckStatus = _FromStudentData }; TimeTableResponse download_TimeTableResponse = new TimeTableResponse(); var json = JsonConvert.SerializeObject(timetableRequest, 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; download_TimeTableResponse = JsonConvert.DeserializeObject <TimeTableResponse>(test.Result); if (download_TimeTableResponse.TimeTable.Count == 0) { return; } int codeMasterTimeTable = await App.Database.save_DownloadTimeTableResponse(download_TimeTableResponse); if (codeMasterTimeTable > 0) { TimeTableAcknowledgementRequest timeTableAcknowledgementRequest = new TimeTableAcknowledgementRequest() { UserID = _UserID, UserType = (int)_userType, TimeTableMasterCode = codeMasterTimeTable }; GeneralProperties.ServicesMethodName = ServiceAPIInfo.request_TimeTableAcknowledgementStatus; url = ServiceAPIInfo.serviceAPI + GeneralProperties.ServicesMethodName; Client.BaseAddress = new Uri(url); Client.Timeout = TimeSpan.FromMilliseconds(ServiceAPIInfo.service_TimeOut); json = JsonConvert.SerializeObject(timeTableAcknowledgementRequest, 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; } else { Console.WriteLine("Time Table Acknowledgement status {0}", responseAPI.StatusCode); } } } else { Console.Write(responseAPI.RequestMessage); } } catch (WebException Ex) { Console.WriteLine(Ex.Message); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public bool logInService(string _emailID, string _password, UserType.enumUserType _userType) { bool CheckLogInAuthentication = false; try { var Client = new HttpClient(); string url = ServiceAPIInfo.serviceAPI + ServiceAPIInfo.loginMethod; LoginRequest loginR = new LoginRequest() { Email = _emailID, Password = _password, //here + 1 because UserType = (int)_userType, DeviceID = DependencyService.Get <DependencyServices.IDependencyService>().DeviceID() //DeviceID = "1234" }; string Json = JsonConvert.SerializeObject(loginR, Formatting.Indented); var contentjson = new StringContent(Json, Encoding.UTF8, ServiceAPIInfo.ContentMediaType); //Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); Client.BaseAddress = new Uri(url); HttpResponseMessage responseAPI = Client.PostAsync(url, contentjson).Result; if (responseAPI.IsSuccessStatusCode == true) { var test = responseAPI.Content.ReadAsStringAsync(); var stringmsg = (object)test.Result; var result = JsonConvert.DeserializeObject <LogInResponse>(test.Result); if (!string.IsNullOrWhiteSpace(result.ToString())) { UserType.currentUserType = _userType; ProfileViewModel.id = result.MobileUser.Code; //save data in logInTable using sqlite SaveLogInData(result); //here is bind itemlist //SaveData(responseData.data.email); CheckLogInAuthentication = true; } else { CheckLogInAuthentication = false; } CheckLogInAuthentication = true; } else { StrMSG = "Unauthorized User !"; CheckLogInAuthentication = false; } return(CheckLogInAuthentication); } catch (WebException ex) { StrMSG = ErrorMsg(ex.ToString()); } catch (ProtocolViolationException ex) { StrMSG = ErrorMsg(ex.ToString()); } catch (AggregateException ex) { StrMSG = ErrorMsg("Server is not responding.."); Console.WriteLine(ex.InnerException.Message); } return(CheckLogInAuthentication); }