public virtual void InsertPhieuGuiHang(PhieuGuiHang item) { if (item == null) { throw new ArgumentNullException("Phiếu gửi hàng"); } _phieuguihangRepository.Insert(item); //lay tong phieu gui hang trong thang cua nha xe hien tai item = GetPhieuGuiById(item.Id); //add by lent: 24-12-2015 var intcount = _phieuguihangRepository.Table.Where(c => c.NhaXeId == item.NhaXeId && c.NgayTao.Month == item.NgayTao.Month && c.NgayTao.Year == item.NgayTao.Year).Count(); if (item.VanPhongGui == null) { item.VanPhongGui = _nhaxeService.GetVanPhongById(item.VanPhongGuiId); } if (item.VanPhongNhan == null) { item.VanPhongNhan = _nhaxeService.GetVanPhongById(item.VanPhongNhanId); } item.MaPhieu = string.Format("{2}{0}{1}", DateTime.Now.ToString("yy"), intcount.ToString().PadLeft(4, '0'), item.VanPhongGui.Ma); if (String.IsNullOrEmpty(item.DiemGui) && item.VanPhongGui != null) { item.DiemGui = item.VanPhongGui.TenVanPhong; } if (String.IsNullOrEmpty(item.DiemTra) && item.VanPhongNhan != null) { item.DiemTra = item.VanPhongNhan.TenVanPhong; } _phieuguihangRepository.Update(item); }