Esempio n. 1
0
        // GET: Admin
        public async Task <ActionResult> Index()
        {
            ViewBag.accept = false;
            if (Session["Taikhoanadmin"] == null)
            {
                return(RedirectToAction("SignIn"));
            }
            HttpResponseMessage responseMessage = await client.GetAsync(url + @"dondathang/");

            List <DonDatHang> list = DonDatHangController.getAllOrder(responseMessage);

            ViewBag.CountOrder = list.Count;

            String dataChart = "";

            // data = ''
            dataChart += list.Where(n => int.Parse(n.TinhTrangDonHang) == Constants.STATUS_ORDER_CONFIRM).Count() + ",";
            // data = '2,'
            dataChart += list.Where(n => int.Parse(n.TinhTrangDonHang) == Constants.STATUS_ORDER_DELIVERY).Count() + ",";
            // data = '2,1,'
            dataChart += list.Where(n => int.Parse(n.TinhTrangDonHang) == Constants.STATUS_ORDER_DELIVERED).Count() + ",";
            // data = '2,1,1'
            dataChart += list.Where(n => int.Parse(n.TinhTrangDonHang) == Constants.STATUS_SHIP_BOOM).Count();

            ViewBag.DataChart = dataChart;


            responseMessage = await client.GetAsync(url + @"khachhang/");

            List <KhachHang> listkh = KhachHangController.getAllCustomer(responseMessage);

            ViewBag.CountCustomer = listkh.Count;

            responseMessage = await client.GetAsync(url + @"chitietdonhang/");

            List <ChiTietDonHang> listctdh = getAllDetailOrder(responseMessage);

            ViewBag.revenue = getRevenue(listctdh);

            responseMessage = await client.GetAsync(url + @"nhanviengiaohang/");

            List <NhanVienGiaoHang> listnv = NhanVienGiaoHangController.getAllNhanVienGH(responseMessage);

            ViewBag.CountShipper = listnv.Count;

            responseMessage = await client.GetAsync(url + @"cuahang/");

            List <Cuahang> listch = CuahangController.getAllCuaHang(responseMessage);

            ViewBag.CountStore = listch.Count;

            responseMessage = await client.GetAsync(url + @"doan/");

            List <DoAn> listda = DoAnController.getAllDoAn(responseMessage);

            ViewBag.CountFood = listda.Count;

            responseMessage = await client.GetAsync(url + @"danhmucdoan/");

            List <DanhMucDoAn> listdm = DanhMucDoAnController.getAllDanhMuc(responseMessage);

            ViewBag.CountMenu = listdm.Count;

            responseMessage = await client.GetAsync(url + @"vitrigiaohang/");

            List <ViTriGiaoHang> listvt = ViTriGiaoHangController.getAllPosition(responseMessage);

            ViewBag.CountPosition = listvt.Count;

            return(View());
        }
        // GET: chiTietDonHAng/Details
        public async Task <ActionResult> Details(int?id, int?MaKH)
        {
            HttpResponseMessage response = await client.GetAsync(url + @"chitietdonhang/" + id);

            if (response.IsSuccessStatusCode)
            {
                var responseData = response.Content.ReadAsStringAsync().Result;
                var settings     = new JsonSerializerSettings
                {
                    NullValueHandling     = NullValueHandling.Ignore,
                    MissingMemberHandling = MissingMemberHandling.Ignore
                };
                var chiTietDonHangs      = JsonConvert.DeserializeObject <List <ChiTietDonHang> >(responseData, settings);
                List <ChiTietDonHang> ds = chiTietDonHangs.ToList();
                // id mdh
                ViewBag.MDH = id;

                // Get total price
                ViewBag.total = getTotal(ds);

                // Get don dat hang
                HttpResponseMessage responseMessage = await client.GetAsync(url + @"dondathang/");

                List <DonDatHang> donDatHangs = getAllOrder(responseMessage);
                DonDatHang        ddh         = donDatHangs.SingleOrDefault(n => n.MaDonHang == id);
                ViewBag.ngaydat   = ddh.NgayDat;
                ViewBag.tinhtrang = ddh.TinhTrangDonHang;
                ViewBag.tg        = ddh.TgGiao;

                //get DoAn
                responseMessage = await client.GetAsync(url + @"doan/");

                List <DoAn>   listda = DoAnController.getAllDoAn(responseMessage);
                List <string> dsTen  = new List <string>();
                foreach (ChiTietDonHang ctdh in ds)
                {
                    string name = listda.Where(n => n.MaDA == ctdh.MaDA).SingleOrDefault().TenDA;
                    dsTen.Add(name);
                }
                //DoAn doAn = listda.Where(n => n.MaDA == );
                ViewBag.nameDa = dsTen;

                // Get name user
                responseMessage = await client.GetAsync(url + @"khachhang/");

                List <KhachHang> list      = KhachHangController.getAllCustomer(responseMessage);
                KhachHang        khachHang = list.Where(n => n.MaKH == MaKH).SingleOrDefault();
                ViewBag.name = khachHang.HoTenKH;
                ViewBag.id   = khachHang.MaKH;
                ViewBag.dtkh = khachHang.DienThoaiKH;

                // Get position
                responseMessage = await client.GetAsync(url + @"vitrigiaohang/");

                List <ViTriGiaoHang> listVt = ViTriGiaoHangController.getAllPosition(responseMessage);
                ViTriGiaoHang        viTri  = listVt.Where(n => n.MaVT == ddh.MaVT).SingleOrDefault();
                ViewBag.vitri = viTri.TenVT;

                //get NVGH
                responseMessage = await client.GetAsync(url + @"nhanviengiaohang/");

                List <NhanVienGiaoHang> listnv   = NhanVienGiaoHangController.getAllNhanVienGH(responseMessage);
                NhanVienGiaoHang        nhanvien = listnv.Where(n => n.MaNV == ddh.MaNV).SingleOrDefault();
                ViewBag.namenv = nhanvien.HoTenNV;
                ViewBag.idnv   = nhanvien.MaNV;
                ViewBag.dtnv   = nhanvien.DienThoaiNV;

                ////get DoAn
                //responseMessage = await client.GetAsync(url + @"doan/");
                //List<DoAn> listda = HTFood.Controllers.DoAnController.getAllDoAn(responseMessage);
                //DoAn doAn = listda.Where(n => n.MaDA == MaDA).SingleOrDefault();
                //ViewBag.nameDa = doAn.TenDA;

                return(View(chiTietDonHangs.ToList()));
            }
            return(View());
        }