Beispiel #1
0
        public IList <SanPhamBanChayTaiCuaHangViewModel> SanPhamBanChayNhatTaiCuaHang()
        {
            IQueryable <HangHoa>                     danhSachHangHoa             = _hangHoaRepo.GetAll();
            IQueryable <ChiTietPhieuBanHang>         danhSachchiTietPhieuBanHang = _chiTietPhieuBanHangRepo.GetAll();
            List <SanPhamBanChayTaiCuaHangViewModel> all = new List <SanPhamBanChayTaiCuaHangViewModel>();

            var phieubanhangs = (from phieubanhang in danhSachchiTietPhieuBanHang
                                 group phieubanhang by phieubanhang.MaHangHoa into phieubanhangGroup
                                 orderby phieubanhangGroup.Sum(i => i.SoLuong) descending
                                 select new
            {
                MaHangHoa = phieubanhangGroup.Key,
                TongSoLuongBan = phieubanhangGroup.Sum(i => i.SoLuong),
                TongTien = phieubanhangGroup.Sum(i => i.ThanhTien)
            }).Take(15).ToList();

            all = (from phieubanhang in phieubanhangs
                   join hanghoa in danhSachHangHoa
                   on phieubanhang.MaHangHoa equals hanghoa.MaHangHoa
                   select new SanPhamBanChayTaiCuaHangViewModel
            {
                maHangHoa = phieubanhang.MaHangHoa,
                tongSoLuongBan = phieubanhang.TongSoLuongBan,
                tongTienBan = phieubanhang.TongTien,
                tenHangHoa = hanghoa.TenHangHoa,
                hinhAnh = hanghoa.HinhAnh
            }).ToList();
            return(all);
        }
Beispiel #2
0
        public IList <ChiTietPhieuBanHangViewModel> danhSachPhieuBanHangTheoMa(int soPhieuBanHang)
        {
            IQueryable <ChiTietPhieuBanHang>    dsChiTietPhieuBanHang = _chiTietPhieuBanHangRepo.GetAll();
            List <ChiTietPhieuBanHangViewModel> all = new List <ChiTietPhieuBanHangViewModel>();

            all = (from chitietphieubanhang in dsChiTietPhieuBanHang
                   join hanghoa in _hangHoaRepo.GetAll()
                   on chitietphieubanhang.MaHangHoa equals hanghoa.MaHangHoa
                   select new
            {
                SoPhieuBanHang = chitietphieubanhang.SoPhieuBanHang,
                MaHangHoa = chitietphieubanhang.MaHangHoa,
                SoLuong = chitietphieubanhang.SoLuong,
                Gia = chitietphieubanhang.Gia,
                ThanhTien = chitietphieubanhang.ThanhTien,
                tenHangHoa = hanghoa.TenHangHoa,
            }).AsEnumerable().Select(x => new ChiTietPhieuBanHangViewModel()
            {
                soPhieuBanHang = x.SoPhieuBanHang,
                maHangHoa      = x.MaHangHoa,
                soLuong        = x.SoLuong,
                gia            = x.Gia,
                thanhTien      = x.ThanhTien,
                tenHangHoa     = x.tenHangHoa,
            }).ToList();

            var information = (from i in all
                               where (i.soPhieuBanHang == soPhieuBanHang)
                               select i).ToList();

            return(information.ToList());
        }