Ejemplo n.º 1
0
        // GET: KhachHang/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            // Init variable
            KhachHang           khachHangs = null;
            HttpResponseMessage response   = await client.GetAsync(url + @"khachhang/" + id);

            if (response.IsSuccessStatusCode)
            {
                //dong hoac mo data table
                ViewBag.accept = false;
                khachHangs     = await response.Content.ReadAsAsync <KhachHang>();

                // Call api
                HttpResponseMessage responseMessage = await client.GetAsync(url + @"vitien/");

                // Get all data from the ViTien table
                List <ViTien> viTiens = ViTienController.getAllViTien(responseMessage);
                // Check data with id customer
                viTiens        = viTiens.Where(n => n.MaKH == id).ToList();
                ViewBag.vitien = viTiens;
                // Get all data from the LichSuGD table
                responseMessage = await client.GetAsync(url + @"lichsugd/");

                List <LichSuGD> lichSuGDs = new List <LichSuGD>();
                foreach (ViTien vt in viTiens)
                {
                    // Check data with id ViTien
                    List <LichSuGD> temp = LichSuGDController.getAllLichSuGD(responseMessage).Where(n => n.MaViTien == vt.MaViTien).ToList();
                    // Is exist
                    if (temp != null)
                    {
                        // Save data
                        foreach (LichSuGD lichSuGD in temp)
                        {
                            lichSuGDs.Add(lichSuGD);
                        }
                    }
                }
                // assign values to variables ViewBag.lsgd
                ViewBag.lsgd = lichSuGDs.ToList();
            }

            // Return
            return(View(khachHangs));
        }
Ejemplo n.º 2
0
        // GET: KhachHang/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            // Init variable
            KhachHang           khachHangs = null;
            HttpResponseMessage response   = await client.GetAsync(url + @"khachhang/" + id);

            if (response.IsSuccessStatusCode)
            {
                //dong hoac mo data table
                ViewBag.accept = false;
                khachHangs     = await response.Content.ReadAsAsync <KhachHang>();

                //List<KhachHang> kh = getAllCustomer(response);
                //KhachHang khs = kh.SingleOrDefault(n => n.MaKH == id);
                //ViewBag.tenkh = khs.HoTenKH;

                // Call api
                HttpResponseMessage responseMessage = await client.GetAsync(url + @"vitien/");

                // Get all data from the ViTien table
                List <ViTien> viTiens = ViTienController.getAllViTien(responseMessage);
                // Check data with id customer
                viTiens        = viTiens.Where(n => n.MaKH == id).ToList();
                ViewBag.vitien = viTiens;
                // Get all data from the LichSuGD table
                responseMessage = await client.GetAsync(url + @"lichsugd/");

                List <LichSuGD> lichSuGDs = new List <LichSuGD>();
                foreach (ViTien vt in viTiens)
                {
                    // Check data with id ViTien
                    List <LichSuGD> temp = LichSuGDController.getAllLichSuGD(responseMessage).Where(n => n.MaViTien == vt.MaViTien).ToList();
                    // Is exist
                    if (temp != null)
                    {
                        // Save data
                        foreach (LichSuGD lichSuGD in temp)
                        {
                            lichSuGDs.Add(lichSuGD);
                        }
                    }
                }
                // assign values to variables ViewBag.lsgd
                ViewBag.lsgd = lichSuGDs.ToList();
                //dsyt
                responseMessage = await client.GetAsync(url + @"dsyeuthich/");

                List <DSYeuThich> dSYeuThiches = getAllDSYT(responseMessage);
                // Check data with id customer
                dSYeuThiches = dSYeuThiches.Where(n => n.MaKH == id).ToList();
                ViewBag.DSYT = dSYeuThiches;
                //getCH
                responseMessage = await client.GetAsync(url + @"cuahang/");

                List <Cuahang> listch = CuahangController.getAllCuaHang(responseMessage);
                List <string>  dsTen  = new List <string>();
                foreach (DSYeuThich dsyt in dSYeuThiches)
                {
                    string namech = listch.Where(n => n.MaCH == dsyt.MaCH).SingleOrDefault().TenCH;
                    dsTen.Add(namech);
                }
                ViewBag.tench = dsTen;
            }

            // Return
            return(View(khachHangs));
        }