// GET: FabricPurchase/Delete/5 public async Task <IActionResult> Delete(long?id) { if (id == null) { return(NotFound()); } FabricPurchaseVM fabricPurchaseVM = new FabricPurchaseVM(); HttpClient client = _helperAPI.InitializeClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token")); HttpResponseMessage res = await client.GetAsync("api/FabricPurchase/" + id); if (res.IsSuccessStatusCode) { var result = res.Content.ReadAsStringAsync().Result; fabricPurchaseVM = JsonConvert.DeserializeObject <FabricPurchaseVM>(result); } if (fabricPurchaseVM == null) { return(NotFound()); } //var fabricPurchaseVM = await _context.FabricPurchaseVM // .Include(f => f.SaleContract) // .FirstOrDefaultAsync(m => m.FabricPurchaseId == id); //if (fabricPurchaseVM == null) //{ // return NotFound(); //} return(View(fabricPurchaseVM)); }
// GET: FabricPurchase/Details/5 public async Task <IActionResult> Details(long?id) { if (id == null) { return(NotFound()); } FabricPurchaseVM fabricPurchaseVM = new FabricPurchaseVM(); 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")); //var content = new StringContent(JsonConvert.SerializeObject(id), Encoding.UTF8, "application/json"); HttpResponseMessage currencyVMRes = await client.GetAsync("api/FabricPurchase/" + 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 fabricPurchaseVM = JsonConvert.DeserializeObject <FabricPurchaseVM>(result); } if (fabricPurchaseVM == null) { return(NotFound()); } return(View(fabricPurchaseVM)); //if (id == null) //{ // return NotFound(); //} //var fabricPurchaseVM = await _context.FabricPurchaseVM // .Include(f => f.SaleContract) // .FirstOrDefaultAsync(m => m.FabricPurchaseId == id); //if (fabricPurchaseVM == null) //{ // return NotFound(); //} //return View(fabricPurchaseVM); }
// GET: FabricPurchase/Edit/5 public async Task <IActionResult> Edit(long?id) { if (id == null) { return(NotFound()); } //var fabricPurchaseVM = await _context.FabricPurchaseVM.FindAsync(id); //if (fabricPurchaseVM == null) //{ // return NotFound(); //} FabricPurchaseVM fabricPurchaseVM = new FabricPurchaseVM(); HttpClient client = _helperAPI.InitializeClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token")); HttpResponseMessage response = await client.GetAsync("api/FabricPurchase/" + id); if (response.IsSuccessStatusCode) { var result = response.Content.ReadAsStringAsync().Result; fabricPurchaseVM = JsonConvert.DeserializeObject <FabricPurchaseVM>(result); } if (fabricPurchaseVM == null) { return(NotFound()); } List <SaleContractVM> saleContractVM = new List <SaleContractVM>(); var contentType = new MediaTypeWithQualityHeaderValue(@"application/json"); client.DefaultRequestHeaders.Accept.Add(contentType); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token")); HttpResponseMessage res = await client.GetAsync("api/SaleContracts"); 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 <List <SaleContractVM> >(result); } ViewData["SaleContractId"] = new SelectList(saleContractVM, "SaleContractId", "SaleContractNumber", fabricPurchaseVM.SaleContractId); //ViewData["SaleContractId"] = new SelectList(_context.SaleContractVM, "SaleContractId", "SaleContractId", fabricPurchaseVM.SaleContractId); return(View(fabricPurchaseVM)); }
public async Task <IActionResult> Create([Bind("FabricPurchaseId,SaleContractId,SaleContractNumber,Weaver,ContQuality,Gstquality,IsConversionContract,ConversionRate,PerPickRate,PerMeterRate,QuantityInMeters,Broker,DeliveryTime,Description,IsActive,DateAdded,DateUpdated")] FabricPurchaseVM fabricPurchaseVM) { HttpClient client = _helperAPI.InitializeClient(); if (ModelState.IsValid) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token")); var content = new StringContent(JsonConvert.SerializeObject(fabricPurchaseVM), Encoding.UTF8, "application/json"); //Task has been cancelled exception occured here, and Api method never hits while debugging HttpResponseMessage response = client.PostAsync("api/FabricPurchase", content).Result; if (response.IsSuccessStatusCode) { return(RedirectToAction("Index")); } //_context.Add(fabricPurchaseVM); //await _context.SaveChangesAsync(); //return RedirectToAction(nameof(Index)); } List <SaleContractVM> saleContractVM = new List <SaleContractVM>(); var contentType = new MediaTypeWithQualityHeaderValue(@"application/json"); client.DefaultRequestHeaders.Accept.Add(contentType); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("Token")); HttpResponseMessage res = await client.GetAsync("api/SaleContracts"); 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 <List <SaleContractVM> >(result); } ViewData["SaleContractId"] = new SelectList(saleContractVM, "SaleContractId", "SaleContractNumber", fabricPurchaseVM.SaleContractId); return(View(fabricPurchaseVM)); }
public async Task <IActionResult> Edit(long id, [Bind("FabricPurchaseId,SaleContractId,SaleContractNumber,Weaver,ContQuality,Gstquality,IsConversionContract,ConversionRate,PerPickRate,PerMeterRate,QuantityInMeters,Broker,DeliveryTime,Description,IsActive,DateAdded,DateUpdated")] FabricPurchaseVM fabricPurchaseVM) { if (id != fabricPurchaseVM.FabricPurchaseId) { return(NotFound()); } if (ModelState.IsValid) { try { HttpClient client = _helperAPI.InitializeClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token")); var content = new StringContent(JsonConvert.SerializeObject(fabricPurchaseVM), Encoding.UTF8, "application/json"); HttpResponseMessage res = await client.PutAsync("api/FabricPurchase/" + id, content); if (res.IsSuccessStatusCode) { return(RedirectToAction("Index")); } //_context.Update(fabricPurchaseVM); //await _context.SaveChangesAsync(); } catch (Exception ex) { throw; } //catch (DbUpdateConcurrencyException) //{ // if (!FabricPurchaseVMExists(fabricPurchaseVM.FabricPurchaseId)) // { // return NotFound(); // } // else // { // throw; // } //} return(RedirectToAction(nameof(Index))); } ViewData["SaleContractId"] = new SelectList(_context.SaleContractVM, "SaleContractId", "SaleContractId", fabricPurchaseVM.SaleContractId); return(View(fabricPurchaseVM)); }