Beispiel #1
0
        //Attachment list
        public async Task<Response> PostAttachment<T>(
           string urlBase,
           string servicePrefix,
           string controller,
           string cookie,
           SearchAttachment search)
        {
            try
            {
                var request = JsonConvert.SerializeObject(search);
                Debug.WriteLine("********request*************");
                Debug.WriteLine(request);
                var content = new StringContent(
                    request,
                    Encoding.UTF8,
                    "application/json");
                var cookieContainer = new CookieContainer();
                var handler = new HttpClientHandler() { CookieContainer = cookieContainer };
                var client = new HttpClient(handler);
                client.BaseAddress = new Uri(urlBase);
                var url = string.Format("{0}{1}", servicePrefix, controller);
                cookieContainer.Add(client.BaseAddress, new Cookie("JSESSIONID", cookie));
                var response = await client.PostAsync(url, content);
                Debug.WriteLine("********response*************");
                Debug.WriteLine(response);
                if (!response.IsSuccessStatusCode)
                {
                    return new Response
                    {
                        IsSuccess = false,
                        Message = response.StatusCode.ToString(),
                    };
                }

                var result = await response.Content.ReadAsStringAsync();
                Debug.WriteLine("********result*************");
                Debug.WriteLine(result);
                //var newRecord = JsonConvert.DeserializeObject<T>(result);
                var list = JsonConvert.DeserializeObject<List<T>>(result, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });

                Debug.WriteLine("+++++++++++++++++++++++++list++++++++++++++++++++++++");
                Debug.WriteLine(list);
                return new Response
                {
                    IsSuccess = true,
                    Message = "OK",
                    Result = list,
                };
            }
            catch (Exception ex)
            {
                return new Response
                {
                    IsSuccess = false,
                    Message = ex.Message,
                };
            }
        }
        public async void GetattachmentSearch()
        {
            var Username = Settings.Username;

            User = JsonConvert.DeserializeObject <User>(Username);

            var cookie = Settings.Cookie;  //.Split(11, 33)
            var res    = cookie.Substring(11, 32);

            /* if (SelectedStatus == null)
             * {
             *   await Application.Current.MainPage.DisplayAlert("Warning", "Please Select Status", "ok");
             *   return;
             * }*/
            if (Patient == null && SelectedStatus == null && Client == null)
            {
                _search = new SearchAttachment
                {
                    criteria4 = "",
                    criteria5 = RequestNum,
                    date      = null,
                    date1     = null,
                    id1       = -1,
                    id3       = -1,
                    order     = "desc",
                    sortedBy  = "request_creation_date",
                    status    = "ALL",
                    offset    = 0,
                    maxResult = MaxResult
                };
            }
            else if (Patient == null && Client == null)
            {
                _search = new SearchAttachment
                {
                    criteria4 = "",
                    criteria5 = RequestNum,
                    date      = null,
                    date1     = null,
                    id1       = -1,
                    id3       = -1,
                    order     = "desc",
                    sortedBy  = "request_creation_date",
                    status    = SelectedStatus.name,
                    offset    = 0,
                    maxResult = MaxResult
                };
            }
            else if (SelectedStatus == null && Client == null)
            {
                _search = new SearchAttachment
                {
                    criteria4 = "",
                    criteria5 = RequestNum,
                    date      = null,
                    date1     = null,
                    id1       = Patient.id,
                    id3       = -1,
                    order     = "desc",
                    sortedBy  = "request_creation_date",
                    status    = "ALL",
                    offset    = 0,
                    maxResult = MaxResult
                };
            }
            else if (SelectedStatus == null && Patient == null)
            {
                _search = new SearchAttachment
                {
                    criteria4 = "",
                    criteria5 = RequestNum,
                    date      = null,
                    date1     = null,
                    id1       = -1,
                    id3       = Client.id,
                    order     = "desc",
                    sortedBy  = "request_creation_date",
                    status    = "ALL",
                    offset    = 0,
                    maxResult = MaxResult
                };
            }
            else if (SelectedStatus == null)
            {
                _search = new SearchAttachment
                {
                    criteria4 = "",
                    criteria5 = RequestNum,
                    date      = null,
                    date1     = null,
                    id1       = Patient.id,
                    id3       = Client.id,
                    order     = "desc",
                    sortedBy  = "request_creation_date",
                    status    = "ALL",
                    offset    = 0,
                    maxResult = MaxResult
                };
            }
            else if (Patient == null)
            {
                _search = new SearchAttachment
                {
                    criteria4 = "",
                    criteria5 = RequestNum,
                    date      = null,
                    date1     = null,
                    id1       = -1,
                    id3       = Client.id,
                    order     = "desc",
                    sortedBy  = "request_creation_date",
                    status    = SelectedStatus.name,
                    offset    = 0,
                    maxResult = MaxResult
                };
            }
            else if (Client == null)
            {
                _search = new SearchAttachment
                {
                    criteria4 = "",
                    criteria5 = RequestNum,
                    date      = null,
                    date1     = null,
                    id1       = Patient.id,
                    id3       = -1,
                    order     = "desc",
                    sortedBy  = "request_creation_date",
                    status    = SelectedStatus.name,
                    offset    = 0,
                    maxResult = MaxResult
                };
            }
            else
            {
                _search = new SearchAttachment
                {
                    criteria4 = "",
                    criteria5 = RequestNum,
                    date      = null,
                    date1     = null,
                    id1       = Patient.id,
                    id3       = Client.id,
                    order     = "desc",
                    sortedBy  = "request_creation_date",
                    status    = SelectedStatus.name,
                    offset    = 0,
                    maxResult = MaxResult
                };
            }

            var response = await apiService.PostAttachment <Attachment>(
                "https://portalesp.smart-path.it",
                "/Portalesp",
                "/referti/search",
                res,
                _search);

            if (!response.IsSuccess)
            {
                IsRefreshing = false;
                await Application.Current.MainPage.DisplayAlert("Error", response.Message, "ok");

                return;
            }
            attachmentsList = (List <Attachment>)response.Result;

            Attachments = new ObservableCollection <Attachment>(attachmentsList);
            if (Attachments.Count() == 0)
            {
                IsVisible = true;
            }
            MessagingCenter.Send(new DialogResultAttachment()
            {
                AttachmentPopup = Attachments
            }, "PopUpData");
            await App.Current.MainPage.Navigation.PopPopupAsync(true);
        }