예제 #1
0
        public async Task Create(PhieuBanHangViewModel obj)
        {
            PhieuBanHang order = new PhieuBanHang
            {
                SoPhieuBanHang = obj.soPhieuBanHang,
                NgayBan        = obj.ngayBan,
                MaNhanVien     = obj.maNhanVien,
                Ghichu         = obj.ghiChu,
                TenKhachHang   = obj.tenKhachHang,
                SoDienThoai    = obj.soDienThoai,
                TongTien       = obj.tongTien,
                TrangThai      = true,
                NgayChinhSua   = DateTime.Now
            };

            order.ChiTetPhieuBanHangs = new List <ChiTietPhieuBanHang>();

            DateTime today = DateTime.Now;
            int      thang = today.Month;
            int      nam   = today.Year;

            foreach (var i in obj.chiTietPhieuBanHang)
            {
                order.ChiTetPhieuBanHangs.Add(i);
                //Sơn
                _hangHoaBus.CapNhatHangHoaKhiTaoPhieuBanHang(i.MaHangHoa, i.SoLuong);
                _hangHoaBus.CapNhatHangHoaVaoBaoCaoTonKhoKhiTaoPhieuBanHang(i.MaHangHoa, i.SoLuong, thang, nam);
            }

            await _phieuBanHangRepo.InsertAsync(order);
        }
        public async Task Update(PhieuDatHang entity)
        {
            DateTime today = DateTime.Now;
            int      thang = today.Month;
            int      nam   = today.Year;

            foreach (var i in entity.ChiTietPhieuDatHangs)
            {
                _hangHoaBus.CapNhatHangHoaKhiTaoPhieuBanHang(i.MaHangHoa, i.SoLuong);
                _hangHoaBus.CapNhapHangHoaVaoBaoCaoTonKhiTaoPhieuBanHang(i.MaHangHoa, i.SoLuong, thang, nam);
            }

            await _phieuDatHangRepo.EditAsync(entity);
        }