// Xác nhận giao hàng public ActionResult XemXacNhanGiaoHang(string doiTacID) { ManagerObiect.DoitacID = doiTacID; ManagerObiect.configAPI = new ConfigAPIModel().getConfig(doiTacID); if (ManagerObiect.configAPI == null) { return(RedirectToAction("ConfigAPI", new { MaNCC = doiTacID })); } HopdongNCCModel model = new HopdongNCCModel(); ViewBag.doitac = doiTacID; ViewBag.HD = new SelectList(model.getMaHD(doiTacID), "Mahd", "Mahd"); return(View()); }
public ActionResult XemXacNhanGiaoHang(Hopdong a, string access_token, string username, string password, string doitac) { NhaCungCapModel modelNCC = new NhaCungCapModel(); HopdongNCCModel modelhd = new HopdongNCCModel(); ViewBag.doitac = doitac; ViewBag.HD = new SelectList(modelhd.getMaHD(doitac), "Mahd", "Mahd"); if (!modelNCC.Checkthanhtoan(a.order_id)) { ModelState.AddModelError("", "Hợp đồng này lúc trước chưa thanh toán"); return(View(a)); } if (access_token == "" || access_token == null) { if ((username != "" && password != "") && (username != null && password != null)) { using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json") ); string authInfo = username + ":" + password; authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo)); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", authInfo); var model = new { supplier_key = a.supplier_key, order_id = a.order_id, product_id = a.product_id, product_quantity = a.product_quantity, product_date = a.product_date }; HttpResponseMessage response = client.PostAsJsonAsync( ManagerObiect.configAPI.LinkXacNhanGiaoHang, model ).Result; if (response.StatusCode == HttpStatusCode.OK) { ModelState.AddModelError("", "Đã ghi nhận thành công"); modelhd.SetXacnhangiaohang(a.order_id); } else { ViewBag.thongbao = "Thất bại " + response.Content.ReadAsStringAsync().Result; ModelState.AddModelError("", ViewBag.thongbao); } } } else { ViewBag.thongbao = "Thông tin nhập không chính xác"; return(View(a)); } } else { using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json") ); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", access_token); var model = new { supplier_key = a.supplier_key, order_id = a.order_id, product_id = a.product_id, product_quantity = a.product_quantity, product_date = a.product_date }; HttpResponseMessage response = client.PostAsJsonAsync( ManagerObiect.configAPI.LinkXacNhanGiaoHang, model ).Result; if (response.StatusCode == HttpStatusCode.OK) { ModelState.AddModelError("", "Đã ghi nhận thành công"); modelhd.SetXacnhangiaohang(a.order_id); } else { ViewBag.thongbao = "Thất bại " + response.Content.ReadAsStringAsync().Result; ModelState.AddModelError("", ViewBag.thongbao); } } } return(View(a)); }