Esempio n. 1
0
        protected async Task GetData(string endPoint = "")
        {
            // CORS policy on server needs to be updated to get response headers
            // https://github.com/dotnet/runtime/issues/42179
            if (String.IsNullOrEmpty(endPoint))
            {
                endPoint = contactsEndPoint;
            }

            var response = await HttpClient.GetAsync(baseUrl + endPoint);

            if (response.IsSuccessStatusCode)
            {
                Contacts   = response.Content.ReadFromJsonAsync <IEnumerable <Contact> >().Result.OrderBy(x => x.ContactId);
                pagingInfo = HeaderParser.FindAndParsePagingInfo(response.Headers);
            }

            if (String.IsNullOrEmpty(pagingInfo.PreviousPageLink))
            {
                previousButtonDisabled = true;
            }
            if (String.IsNullOrEmpty(pagingInfo.NextPageLink))
            {
                nextButtonDisabled = true;
            }

            StateHasChanged();
        }
Esempio n. 2
0
        public async Task <ActionResult> Contact()
        {
            ViewBag.Message = "Calling web api";


            var client = MedicoHttpClient.GetClient();

            var model = new QuestionViewModel();

            HttpResponseMessage egsResponse = await client.GetAsync("api/questions");

            if (egsResponse.IsSuccessStatusCode)
            {
                string content = await egsResponse.Content.ReadAsStringAsync();

                // get the paging info from the header
                var pagingInfo = HeaderParser.FindAndParsePagingInfo(egsResponse.Headers);

                var lstQuestions = JsonConvert.DeserializeObject <IEnumerable <Model.Question> >(content);

                var pagedQuestionList = new StaticPagedList <Model.Question>(lstQuestions, pagingInfo.CurrentPage,
                                                                             pagingInfo.PageSize, pagingInfo.TotalCount);

                model.Questions  = pagedQuestionList;
                model.PagingInfo = pagingInfo;
            }
            else
            {
                return(Content("An error occurred."));
            }

            return(View(model));
        }
Esempio n. 3
0
        // GET: Movie
        public async Task <ActionResult> Index(int?page = 1, string search = "")
        {
            var model = new MoviesViewModel();

            var client = MovieInfoHttpClient.GetClient();
            HttpResponseMessage resp = await client.GetAsync(string.Concat("api/movies?search=", search, "&page=", page, "&pagesize=5"));

            if (resp.IsSuccessStatusCode)
            {
                string content = await resp.Content.ReadAsStringAsync();

                var movResponse = JsonConvert.DeserializeObject <IEnumerable <DTO.Movie> >(content);

                var pageInfo     = HeaderParser.FindAndParsePagingInfo(resp.Headers);
                var pagedMovList = new StaticPagedList <DTO.Movie>(
                    movResponse,
                    pageInfo.CurrentPageNumber,
                    pageInfo.PageSize,
                    pageInfo.TotalRecordCount);

                model.Movies     = pagedMovList;
                model.PagingInfo = pageInfo;

                return(View(model));
            }
            else
            {
                return(Content("An Error occurred."));
            }
        }
Esempio n. 4
0
        public async Task <ActionResult> MyAnswers(int?page, string userId)
        {
            var client = MedicoHttpClient.GetClient();

            var model   = new MyAnswerViewModel();
            var api_url = "api/myanswers?page=" + page + "&userId=" + userId;

            HttpResponseMessage egsResponse = await client.GetAsync(api_url);

            if (egsResponse.IsSuccessStatusCode)
            {
                string content = await egsResponse.Content.ReadAsStringAsync();

                // get the paging info from the header
                var pagingInfo = HeaderParser.FindAndParsePagingInfo(egsResponse.Headers);

                var lstAnswers = JsonConvert.DeserializeObject <IEnumerable <Model.Answer> >(content);

                var pagedQuestionList = new StaticPagedList <Model.Answer>(lstAnswers, pagingInfo.CurrentPage,
                                                                           pagingInfo.PageSize, pagingInfo.TotalCount);

                //var pagedQuestionList = lstQuestions.ToPagedList(pagingInfo.CurrentPage, pagingInfo.PageSize);

                model.MyAnswers  = pagedQuestionList;
                model.PagingInfo = pagingInfo;
            }
            else
            {
                return(Content("An error occurred."));
            }
            ViewBag.userId = userId;
            return(View(model));
        }
Esempio n. 5
0
        public async Task <ActionResult> Index(int?page = 1)
        {
            var client = ExpenseTrackerHttpClient.GetClient();

            var model = new ExpenseGroupsViewModel();

            // Calling the GET method on API
            HttpResponseMessage egsResponse = await client.GetAsync("api/expensegroupstatusses");

            if (egsResponse.IsSuccessStatusCode)
            {
                string egsContent = await egsResponse.Content.ReadAsStringAsync();

                var lstExpenseGroupStatusses = JsonConvert
                                               .DeserializeObject <IEnumerable <ExpenseGroupStatus> >(egsContent);

                model.ExpenseGroupStatusses = lstExpenseGroupStatusses;
            }
            else
            {
                return(Content("An error occurred."));
            }

            // Without sorting
            //HttpResponseMessage response = await client.GetAsync("api/expensegroups");

            // With sorting. Expense groups will be sorted first by status code and then by title
            //HttpResponseMessage response = await client.GetAsync("api/expensegroups?sort=expensegroupstatusid,title");

            // With paging. We already have suport for paging in API but we need to add new support in the client.
            // I added PagingInfo.cs & HeaderParser.cs helper classes to implement paging on this MVC client.
            HttpResponseMessage response = await client.GetAsync("api/expensegroups?sort=expensegroupstatusid,title&page=" + page + "&pagesize=5");

            if (response.IsSuccessStatusCode)
            {
                string content = await response.Content.ReadAsStringAsync();

                var pagingInfo       = HeaderParser.FindAndParsePagingInfo(response.Headers); // Also, added NuGet package pagedlist.mvc to implement paging
                var lstExpenseGroups = JsonConvert.DeserializeObject <IEnumerable <ExpenseGroup> >(content);

                var pagedExpenseGroupsList = new StaticPagedList <ExpenseGroup>(lstExpenseGroups,
                                                                                pagingInfo.CurrentPage,
                                                                                pagingInfo.PageSize,
                                                                                pagingInfo.TotalCount);

                model.ExpenseGroups = pagedExpenseGroupsList;
                model.PagingInfo    = pagingInfo;
            }
            else
            {
                return(Content("An error occurred."));
            }

            return(View(model));
        }
        // GET: ExpenseGroup

        public async Task <ActionResult> Index(int?page = 1)
        {
            var client = ExpenseTrackerHttpClient.GetClient();

            var model = new ExpenseGroupsViewModel();

            var egsResponse = await client.GetAsync("api/expensegroupstatusses");

            if (egsResponse.IsSuccessStatusCode)
            {
                string egsContent = await egsResponse.Content.ReadAsStringAsync();

                var lstExpenseGroupStatusses = JsonConvert
                                               .DeserializeObject <IEnumerable <ExpenseGroupStatus> >(egsContent);

                model.ExpenseGroupStatusses = lstExpenseGroupStatusses;
            }
            else
            {
                return(Content("An error occurred."));
            }


            // HttpResponseMessage response = await client.GetAsync("api/expensegroups?sort=expensegroupstatusid,title");

            HttpResponseMessage response =
                await client.GetAsync("api/expensegroups?sort=expensegroupstatusid,title&page=" + page + "&pagesize=5");

            if (response.IsSuccessStatusCode)
            {
                string content = await response.Content.ReadAsStringAsync();

                var pagingInfo = HeaderParser.FindAndParsePagingInfo(response.Headers);

                var lstExpenseGroups = JsonConvert.DeserializeObject <IEnumerable <ExpenseGroup> >(content);

                // model.ExpenseGroups = lstExpenseGroups;

                var pagedExpenseGroupsList = new StaticPagedList <ExpenseGroup>(lstExpenseGroups,
                                                                                pagingInfo.CurrentPage,
                                                                                pagingInfo.PageSize, pagingInfo.TotalCount);


                model.ExpenseGroups = pagedExpenseGroupsList;
                model.PagingInfo    = pagingInfo;
            }
            else
            {
                return(Content("An error occurred."));
            }


            return(View(model));
        }
Esempio n. 7
0
        public async Task <ActionResult> Index(int?page = 1)
        {
            //calling get or post happen as async mode
            var client = ExpenseTrackerHttpClient.GetClient();

            var model = new ExpenseGroupsViewModel();
            // GET Expense Group Status
            var egsResponse = await client.GetAsync("api/expensegroupstatusses");

            if (egsResponse.IsSuccessStatusCode)
            {
                string egsContent = await egsResponse.Content.ReadAsStringAsync();

                //deserelized the response to get oreginal data
                var lstExpenseGroupStatusses =
                    JsonConvert.DeserializeObject <IEnumerable <ExpenseGroupStatus> >(egsContent);
                model.ExpenseGroupStatusses = lstExpenseGroupStatusses;
            }
            else
            {
                return(Content("An error occurred."));
            }

            // GET Expense Group

            HttpResponseMessage response =
                await client.GetAsync("api/expensegroups?sort=expensegroupstatusid,title&page=" + page + "&pagesize=5");     //done sorting

            if (response.IsSuccessStatusCode)
            {
                string content = await response.Content.ReadAsStringAsync();

                //paging
                var pagingInfo = HeaderParser.FindAndParsePagingInfo(response.Headers);
                //deserelized the response and get the data as IEnumerable

                var lstExpenseGroups =
                    JsonConvert.DeserializeObject <IEnumerable <ExpenseGroup> >(content);
                //then it convert to IPagedList inerface for pageing
                var pagedExpenseGroupsList = new StaticPagedList <ExpenseGroup>(lstExpenseGroups,
                                                                                pagingInfo.CurrentPage,
                                                                                pagingInfo.PageSize, pagingInfo.TotalCount);

                model.ExpenseGroups = pagedExpenseGroupsList;
                model.PagingInfo    = pagingInfo;
            }
            else
            {
                return(Content("An error occured."));
            }
            return(View(model));
        }
        public async Task <ActionResult> Index(int?page = 1)
        {
            var client = ExpenseTrackerHttpClient.GetClient();

            var model = new ExpenseGroupsViewModel();

            HttpResponseMessage egsResponse = await client.GetAsync("api/expensegroupstatusses");

            if (egsResponse.IsSuccessStatusCode)
            {
                string egsContent = await egsResponse.Content.ReadAsStringAsync();

                var lstExpenseGroupStatusses = JsonConvert.DeserializeObject <IEnumerable <ExpenseGroupStatus> >(egsContent);
                model.ExpenseGroupStatusses = lstExpenseGroupStatusses;
            }
            else
            {
                return(Content("An error occurred."));
            }

            string userId = (this.User.Identity as ClaimsIdentity).FindFirst("unique_user_key").Value;

            HttpResponseMessage response = await client.GetAsync("api/expensegroups?sort=expensegroupstatusid"
                                                                 + ",title&page=" + page + "&pagesize=5&userid=" + userId);


            if (response.IsSuccessStatusCode)
            {
                string content = await response.Content.ReadAsStringAsync();

                // get the paging info from the header
                var pagingInfo = HeaderParser.FindAndParsePagingInfo(response.Headers);

                var lstExpenseGroups = JsonConvert.DeserializeObject <IEnumerable <ExpenseGroup> >(content);

                var pagedExpenseGroupsList = new StaticPagedList <ExpenseGroup>(lstExpenseGroups, pagingInfo.CurrentPage,
                                                                                pagingInfo.PageSize, pagingInfo.TotalCount);

                model.ExpenseGroups = pagedExpenseGroupsList;
                model.PagingInfo    = pagingInfo;
            }
            else
            {
                return(Content("An error occurred."));
            }


            return(View(model));
        }
Esempio n. 9
0
        public async Task <ActionResult> IndexWithSearch(string textLike, int?page)
        {
            var client = MedicoHttpClient.GetClient();
            //var client = new HttpClient();
            //client.BaseAddress = new System.Uri("http://localhost:2627/");


            var model = new QuestionViewModel();

            string _textlike = textLike == null ? "" : textLike;
            var    api_url   = "";

            if (page == null)
            {
                api_url = "api/questionslike?textlike=" + _textlike;
            }
            else
            {
                api_url = "api/questionslike?textlike=" + _textlike + "&page=" + page;
            }

            HttpResponseMessage egsResponse = await client.GetAsync(api_url);

            if (egsResponse.IsSuccessStatusCode)
            {
                string content = await egsResponse.Content.ReadAsStringAsync();

                // get the paging info from the header
                var pagingInfo = HeaderParser.FindAndParsePagingInfo(egsResponse.Headers);

                var lstQuestions = JsonConvert.DeserializeObject <IEnumerable <Model.Question> >(content);

                var pagedQuestionList = new StaticPagedList <Model.Question>(lstQuestions, pagingInfo.CurrentPage,
                                                                             pagingInfo.PageSize, pagingInfo.TotalCount);

                //var pagedQuestionList = lstQuestions.ToPagedList(pagingInfo.CurrentPage, pagingInfo.PageSize);

                model.Questions  = pagedQuestionList;
                model.PagingInfo = pagingInfo;
            }
            else
            {
                return(Content("An error occurred."));
            }

            ViewBag.TextLike = textLike;
            return(View(model));
        }
Esempio n. 10
0
        public async Task <ActionResult> Index(int?page = 1)
        {
            var ExpenseGroupsVM = new ExpenseGroupsViewModel();

            var client = PWETHttpClient.GetClient();

            //Statusses
            HttpResponseMessage egssResponse = await client.GetAsync("api/expensegroupstatusses");

            if (egssResponse.IsSuccessStatusCode)
            {
                string egsContent = await egssResponse.Content.ReadAsStringAsync();

                var lstExpensesGroupsStatus = JsonConvert.DeserializeObject <IEnumerable <ExpenseGroupStatus> >(egsContent);

                ExpenseGroupsVM.ExpenseGroupStatus = lstExpensesGroupsStatus;
            }
            else
            {
                return(Content("An error has occurred"));
            }

            //Expenses
            HttpResponseMessage Response = await client.GetAsync("api/expensegroup?sort=expensegroupstatusid,title&page=" + page + "&pagesize=5");

            if (Response.IsSuccessStatusCode)
            {
                string content = await Response.Content.ReadAsStringAsync();

                var pagingInfo = HeaderParser.FindAndParsePagingInfo(Response.Headers);

                var lstExpenseGroups       = JsonConvert.DeserializeObject <IEnumerable <ExpenseGroup> >(content);
                var pagedListExpenseGroups = new StaticPagedList <ExpenseGroup>(lstExpenseGroups, pagingInfo.CurrentPage, pagingInfo.PageSize, pagingInfo.TotalCount);

                ExpenseGroupsVM.ExpenseGroup = pagedListExpenseGroups;
                ExpenseGroupsVM.PagingInfo   = pagingInfo;
            }
            else
            {
                return(Content("An error occurred."));
            }

            return(View(ExpenseGroupsVM));
        }
Esempio n. 11
0
        public async Task <ActionResult> GetQuestionsByTag(int page, int tagId, string tagName)
        {
            var client = MedicoHttpClient.GetClient();

            var model = new QuestionViewModel();

            var api_url = "api/questionsbytag?page=" + page + "&tagId=" + tagId;

            HttpResponseMessage egsResponse = await client.GetAsync(api_url);

            if (egsResponse.IsSuccessStatusCode)
            {
                string content = await egsResponse.Content.ReadAsStringAsync();

                // get the paging info from the header
                var pagingInfo = HeaderParser.FindAndParsePagingInfo(egsResponse.Headers);

                var lstQuestions = JsonConvert.DeserializeObject <IEnumerable <Model.Question> >(content);

                var pagedQuestionList = new StaticPagedList <Model.Question>(lstQuestions, pagingInfo.CurrentPage,
                                                                             pagingInfo.PageSize, pagingInfo.TotalCount);

                //var pagedQuestionList = lstQuestions.ToPagedList(pagingInfo.CurrentPage, pagingInfo.PageSize);

                model.Questions  = pagedQuestionList;
                model.PagingInfo = pagingInfo;
            }
            else
            {
                return(Content("An error occurred."));
            }

            ViewBag.tagId   = tagId;
            ViewBag.tagName = tagName;
            return(View(model));
        }
        public async Task <ActionResult> Index(int?page = 1)
        {
            var client = sRecipeHttpClient.GetClient();
            var model  = new RecipesListViewModel();
            HttpResponseMessage response = await client.GetAsync("api/recipes");

            if (response.IsSuccessStatusCode)
            {
                string content = await response.Content.ReadAsStringAsync();

                var pagingInfo = HeaderParser.FindAndParsePagingInfo(response.Headers);
                var lstRecipes = JsonConvert.DeserializeObject <IEnumerable <Recipe> >(content);
                var pagedList  = new StaticPagedList <Recipe>(lstRecipes, pagingInfo.CurrentPage,
                                                              pagingInfo.PageSize, pagingInfo.TotalCount
                                                              );
                model.Recipes    = pagedList;
                model.PagingInfo = pagingInfo;
            }
            else
            {
                return(Content("An error ocurred."));
            }
            return(View(model));
        }