public async Task <IActionResult> ManageQoutes(bool isDeleteFailed, string error) { var user = await StaticDataHandler.GetSessionDetails(); var requestUrl = $"{BaseUrl}{apiUriQoute}/GetAllQoutesForAdmin"; QouteVM qouteVM = new QouteVM(_configuration); using (var client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", user.Token); client.BaseAddress = new Uri(requestUrl); HttpResponseMessage response = await client.GetAsync(requestUrl); if (response.StatusCode == HttpStatusCode.OK) { if (isDeleteFailed) //This is coming from delete function if anything wrong happens there, throw error { qouteVM.OutputHandler.IsErrorOccured = true; if (string.IsNullOrEmpty(error)) { qouteVM.OutputHandler.Message = "Something went wrong, Delete failed. Check if related records exist e.g events or Media"; } else { qouteVM.OutputHandler.Message = error; } } else { qouteVM.OutputHandler.IsErrorOccured = false; } qouteVM.QouteDTO = await response.Content.ReadAsAsync <IEnumerable <QouteDTO> >(); } else if (response.StatusCode == HttpStatusCode.Unauthorized) { qouteVM.OutputHandler.IsErrorOccured = true; qouteVM.OutputHandler.Message = "You're not Authorized to perfom this task"; } else { qouteVM.OutputHandler = await response.Content.ReadAsAsync <OutputHandler>(); }; return(View(qouteVM)); } }
public async Task <IActionResult> Index(int?page) { var requestUrl = $"{BaseUrl}{apiUriQoute}/GetAllQoutes?isFiltered={true}"; QouteVM qouteVM = new QouteVM(_configuration); using (var client = new HttpClient()) { client.BaseAddress = new Uri(requestUrl); HttpResponseMessage response = await client.GetAsync(requestUrl); OutputHandler outputHandler = new OutputHandler(); if (response.StatusCode == HttpStatusCode.OK) { qouteVM.QouteDTO = await response.Content.ReadAsAsync <IEnumerable <QouteDTO> >(); } ; qouteVM.PaginatedQoutes = await PaginatedList <QouteDTO> .CreateAsync(qouteVM.QouteDTO, page ?? 1, 50); // qouteVM.List = Extensions.Batch(qouteVM.QouteDTO.OrderByDescending(x => x.QouteId), 7); qouteVM.PageSetup.PageTitle = "Quotes"; return(View(qouteVM)); } }