Ejemplo n.º 1
0
        public static Task <FillUpAttendanceModel> GetFillUpAttendance(int Standard, int Class, int DateCounter)
        {
            var result = new TaskCompletionSource <FillUpAttendanceModel>();
            var token  = "";

            Device.BeginInvokeOnMainThread(async() =>
            {
                try
                {
                    using (var client = new HttpClient())
                    {
                        client.BaseAddress = new Uri(Constants.ServiceUrl);

                        if (SchoolManagementContext.TokenResponseModel != null)
                        {
                            token = SchoolManagementContext.TokenResponseModel.Token;
                        }
                        if (string.IsNullOrEmpty(token))
                        {
                            client.DefaultRequestHeaders.Add("Login-Token", string.Format("{0}-login", DateTime.Now.ToString("d")));
                        }
                        else
                        {
                            client.DefaultRequestHeaders.Add("Authorization-Token", token);
                        }

                        string requestUri = string.Format("api/AttendanceDetail/{0}/{1}/{2}", Standard, Class, DateCounter);

                        var response = await client.GetAsync(requestUri);

                        FillUpAttendanceModel model = new FillUpAttendanceModel();

                        if (response.IsSuccessStatusCode)
                        {
                            var content = await response.Content.ReadAsStringAsync();
                            if (content != "null")
                            {
                                result.SetResult(JsonConvert.DeserializeObject <FillUpAttendanceModel>(content));
                            }
                            else
                            {
                                result.SetResult(model);
                            }
                        }
                        else
                        {
                            result.SetResult(model);
                        }
                    }
                }
                catch (Exception ex)
                {
                    result.SetResult(new FillUpAttendanceModel());
                }
            });
            return(result.Task);
        }
Ejemplo n.º 2
0
        public static Task <bool> SaveStudentAttendance(FillUpAttendanceModel fillUpAttendanceModel)
        {
            var result = new TaskCompletionSource <bool>();
            var token  = "";

            Device.BeginInvokeOnMainThread(async() =>
            {
                try
                {
                    using (var client = new HttpClient())
                    {
                        client.BaseAddress = new Uri(Constants.ServiceUrl);

                        if (SchoolManagementContext.TokenResponseModel != null)
                        {
                            token = SchoolManagementContext.TokenResponseModel.Token;
                        }
                        if (string.IsNullOrEmpty(token))
                        {
                            client.DefaultRequestHeaders.Add("Login-Token", string.Format("{0}-login", DateTime.Now.ToString("d")));
                        }
                        else
                        {
                            client.DefaultRequestHeaders.Add("Authorization-Token", token);
                        }

                        string requestUri = string.Format("api/StudentAttendance");

                        var response = await client.PostAsync(requestUri, fillUpAttendanceModel, new JsonMediaTypeFormatter());

                        if (response.StatusCode == System.Net.HttpStatusCode.OK)
                        {
                            result.SetResult(true);
                        }
                        else
                        {
                            result.SetResult(false);
                        }
                    }
                }
                catch (Exception ex)
                {
                    result.SetResult(false);
                }
            });
            return(result.Task);
        }