// GET: BankInfo/Details/5 public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } BankInfoVM bankInfoVM = new BankInfoVM(); HttpClient client = _helperAPI.InitializeClient(); var contentType = new MediaTypeWithQualityHeaderValue("application/json"); client.DefaultRequestHeaders.Accept.Add(contentType); //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", TempData.Peek("Token").ToString()); //var content = new StringContent(JsonConvert.SerializeObject(id), Encoding.UTF8, "application/json"); HttpResponseMessage currencyVMRes = await client.GetAsync("api/BankInfo/" + id); if (currencyVMRes.StatusCode == HttpStatusCode.Unauthorized) { ViewBag.Message = "Unauthorized!"; } //Checking the response is successful or not which is sent using HttpClient if (currencyVMRes.IsSuccessStatusCode) { //Storing the response details recieved from web api var result = currencyVMRes.Content.ReadAsStringAsync().Result; //Deserializing the response recieved from web api and storing into the Role list bankInfoVM = JsonConvert.DeserializeObject <BankInfoVM>(result); } if (bankInfoVM == null) { return(NotFound()); } return(View(bankInfoVM)); //if (id == null) //{ // return NotFound(); //} //var bankInfoVM = await _context.BankInfoVM // .FirstOrDefaultAsync(m => m.Id == id); //if (bankInfoVM == null) //{ // return NotFound(); //} //return View(bankInfoVM); }
// GET: BankInfo/Delete/5 public async Task <IActionResult> Delete(int?id) { if (id == null) { return(NotFound()); } BankInfoVM bankInfoVM = new BankInfoVM(); HttpClient client = _helperAPI.InitializeClient(); //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", TempData.Peek("Token").ToString()); HttpResponseMessage res = await client.GetAsync("api/BankInfo/" + id); if (res.IsSuccessStatusCode) { var result = res.Content.ReadAsStringAsync().Result; bankInfoVM = JsonConvert.DeserializeObject <BankInfoVM>(result); } if (bankInfoVM == null) { return(NotFound()); } return(View(bankInfoVM)); //if (id == null) //{ // return NotFound(); //} //var bankInfoVM = await _context.BankInfoVM // .FirstOrDefaultAsync(m => m.Id == id); //if (bankInfoVM == null) //{ // return NotFound(); //} //return View(bankInfoVM); }
public async Task <IActionResult> Create([Bind("Id,Title,BankName,AccountNo,Iban,BranchCode,BranchAddress,SwiftCode")] BankInfoVM bankInfoVM) { if (ModelState.IsValid) { HttpClient client = _helperAPI.InitializeClient(); //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", TempData.Peek("Token").ToString()); var content = new StringContent(JsonConvert.SerializeObject(bankInfoVM), Encoding.UTF8, "application/json"); //Task has been cancelled exception occured here, and Api method never hits while debugging HttpResponseMessage res = client.PostAsync("api/BankInfo", content).Result; if (res.IsSuccessStatusCode) { return(RedirectToAction("Index")); } } return(View(bankInfoVM)); //if (ModelState.IsValid) //{ // _context.Add(bankInfoVM); // await _context.SaveChangesAsync(); // return RedirectToAction(nameof(Index)); //} //return View(bankInfoVM); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Title,BankName,AccountNo,Iban,BranchCode,BranchAddress,SwiftCode")] BankInfoVM bankInfoVM) { if (id != bankInfoVM.Id) { return(NotFound()); } if (ModelState.IsValid) { try { HttpClient client = _helperAPI.InitializeClient(); //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", TempData.Peek("Token").ToString()); var content = new StringContent(JsonConvert.SerializeObject(bankInfoVM), Encoding.UTF8, "application/json"); HttpResponseMessage res = await client.PutAsync("api/BankInfo/" + id, content); if (res.IsSuccessStatusCode) { return(RedirectToAction("Index")); } } catch (DbUpdateConcurrencyException) { //if (!RoleVMExists(roleVM.Id)) //{ // return NotFound(); //} //else //{ throw; //} } return(RedirectToAction(nameof(Index))); } return(View(bankInfoVM)); //if (id != bankInfoVM.Id) //{ // return NotFound(); //} //if (ModelState.IsValid) //{ // try // { // _context.Update(bankInfoVM); // await _context.SaveChangesAsync(); // } // catch (DbUpdateConcurrencyException) // { // if (!BankInfoVMExists(bankInfoVM.Id)) // { // return NotFound(); // } // else // { // throw; // } // } // return RedirectToAction(nameof(Index)); //} //return View(bankInfoVM); }
// GET: SaleContract/Details/5 public async Task <IActionResult> Details(long?id) { if (id == null) { return(NotFound()); } SaleContractVM saleContractVM = new SaleContractVM(); HttpClient client = _helperAPI.InitializeClient(); //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", TempData.Peek("Token").ToString()); HttpResponseMessage res = await client.GetAsync("api/SaleContracts/" + id); if (res.StatusCode == HttpStatusCode.Unauthorized) { ViewBag.Message = "Unauthorized!"; } //Checking the response is successful or not which is sent using HttpClient if (res.IsSuccessStatusCode) { //Storing the response details recieved from web api var result = res.Content.ReadAsStringAsync().Result; //Deserializing the response recieved from web api and storing into the Role list saleContractVM = JsonConvert.DeserializeObject <SaleContractVM>(result); } if (saleContractVM == null) { return(NotFound()); } #region Get Sale Contract Items List <SaleContractItemVM> saleContractItemVM = new List <SaleContractItemVM>(); var contentType = new MediaTypeWithQualityHeaderValue("application/json"); client.DefaultRequestHeaders.Accept.Add(contentType); //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token")); HttpResponseMessage res1 = await client.GetAsync("api/SaleContractItems/GetSaleContractItemBySaleContractId/" + id); if (res1.StatusCode == HttpStatusCode.Unauthorized) { ViewBag.Message = "Unauthorized!"; } //Checking the response is successful or not which is sent using HttpClient if (res1.IsSuccessStatusCode) { //Storing the response details recieved from web api var result = res1.Content.ReadAsStringAsync().Result; //Deserializing the response recieved from web api and storing into the role list saleContractItemVM = JsonConvert.DeserializeObject <List <SaleContractItemVM> >(result); foreach (var item in saleContractItemVM) { #region Unit UnitVM unitVM = new UnitVM(); //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token")); HttpResponseMessage resUnit = await client.GetAsync("api/Units/" + item.UnitId); if (resUnit.StatusCode == HttpStatusCode.Unauthorized) { ViewBag.Message = "Unauthorized!"; } //Checking the response is successful or not which is sent using HttpClient if (resUnit.IsSuccessStatusCode) { //Storing the response details recieved from web api var resultUnit = resUnit.Content.ReadAsStringAsync().Result; //Deserializing the response recieved from web api and storing into the Role list unitVM = JsonConvert.DeserializeObject <UnitVM>(resultUnit); item.Unit = unitVM; } if (unitVM == null) { return(NotFound()); } #endregion } } //returning the role list to view #endregion saleContractVM.SaleContractItems = saleContractItemVM; #region Customer Information CustomerVM customerVM = new CustomerVM(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token")); HttpResponseMessage res2 = await client.GetAsync("api/Customers/" + saleContractVM.CustomerId); if (res2.StatusCode == HttpStatusCode.Unauthorized) { ViewBag.Message = "Unauthorized!"; } //Checking the response is successful or not which is sent using HttpClient if (res2.IsSuccessStatusCode) { //Storing the response details recieved from web api var result = res2.Content.ReadAsStringAsync().Result; //Deserializing the response recieved from web api and storing into the Role list customerVM = JsonConvert.DeserializeObject <CustomerVM>(result); } if (customerVM == null) { return(NotFound()); } saleContractVM.Customer = customerVM; #endregion #region Currency CurrencyVM currencyVM = new CurrencyVM(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token")); //var content = new StringContent(JsonConvert.SerializeObject(id), Encoding.UTF8, "application/json"); HttpResponseMessage currencyVMRes = await client.GetAsync("api/Currencies/" + saleContractVM.CurrencyId); if (currencyVMRes.StatusCode == HttpStatusCode.Unauthorized) { ViewBag.Message = "Unauthorized!"; } //Checking the response is successful or not which is sent using HttpClient if (currencyVMRes.IsSuccessStatusCode) { //Storing the response details recieved from web api var result = currencyVMRes.Content.ReadAsStringAsync().Result; //Deserializing the response recieved from web api and storing into the Role list currencyVM = JsonConvert.DeserializeObject <CurrencyVM>(result); } if (currencyVM == null) { return(NotFound()); } saleContractVM.Currency = currencyVM; #endregion #region Bank Details BankInfoVM bankInfoVM = new BankInfoVM(); client.DefaultRequestHeaders.Accept.Add(contentType); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token")); //var content = new StringContent(JsonConvert.SerializeObject(id), Encoding.UTF8, "application/json"); HttpResponseMessage bankInfoVMRes = await client.GetAsync("api/BankInfo/" + saleContractVM.BankDetails); if (bankInfoVMRes.StatusCode == HttpStatusCode.Unauthorized) { ViewBag.Message = "Unauthorized!"; } //Checking the response is successful or not which is sent using HttpClient if (bankInfoVMRes.IsSuccessStatusCode) { //Storing the response details recieved from web api var result = bankInfoVMRes.Content.ReadAsStringAsync().Result; //Deserializing the response recieved from web api and storing into the Role list bankInfoVM = JsonConvert.DeserializeObject <BankInfoVM>(result); saleContractVM.BankDetailsNavigation = bankInfoVM; } #endregion Bank Details return(View(saleContractVM)); //if (id == null) //{ // return NotFound(); //} //var saleContractVM = await _context.SaleContractVM // .Include(s => s.Currency) // .Include(s => s.Customer) // .FirstOrDefaultAsync(m => m.SaleContractId == id); //if (saleContractVM == null) //{ // return NotFound(); //} //return View(saleContractVM); }