Пример #1
0
        public async Task HuyPhieuBanHang(object editModel)
        {
            try
            {
                PhieuBanHang editPhieuBanHang = (PhieuBanHang)editModel;
                var          phieuBanHang     = dbContext.ChiTietPhieuBanHanges.Where(x => x.SoPhieuBanHang == editPhieuBanHang.SoPhieuBanHang);

                foreach (var i in phieuBanHang)
                {
                    _hangHoaBus.CapNhapHangHoaVaoBaoCaoTonKhiHuyPhieuBanHang(i.MaHangHoa, i.SoLuong, editPhieuBanHang.NgayBan.Month, editPhieuBanHang.NgayBan.Year);
                    _hangHoaBus.CapNhatHangHoaKhiXoaPhieuBanHang(i.MaHangHoa, i.SoLuong);
                }
                editPhieuBanHang.TrangThai = false;
                await _phieuBanHangRepo.EditAsync(editPhieuBanHang);
            }
            catch (Exception)
            {
            }
        }
        public async Task DeletePhieuDatHang(object deleteModel)
        {
            PhieuDatHang xoaPhieuDatHang = (PhieuDatHang)deleteModel;

            xoaPhieuDatHang.TrangThai    = false;
            xoaPhieuDatHang.NgayChinhSua = DateTime.Now;

            var phieuDatHang = dbContext.ChiTietPhieuDatHanges.Where(x => x.SoPhieuDatHang == xoaPhieuDatHang.SoPhieuDatHang);
            int thang        = dbContext.PhieuDatHangs.SingleOrDefault(x => x.SoPhieuDatHang == xoaPhieuDatHang.SoPhieuDatHang).NgayDat.Month;
            int nam          = dbContext.PhieuDatHangs.SingleOrDefault(x => x.SoPhieuDatHang == xoaPhieuDatHang.SoPhieuDatHang).NgayDat.Year;

            foreach (var i in phieuDatHang)
            {
                _hangHoaBus.CapNhatHangHoaKhiXoaPhieuBanHang(i.MaHangHoa, i.SoLuong);
                _hangHoaBus.CapNhapHangHoaVaoBaoCaoTonKhiHuyPhieuBanHang(i.MaHangHoa, i.SoLuong, thang, nam);
            }

            await _phieuDatHangRepo.EditAsync(xoaPhieuDatHang);
        }