public long Add(Vendor obj) { if (IsDuplicate(obj.VendorCode, obj.Id, obj.CustomerId) == false) { return(_vendorRepository.Add(obj)); } else { Expression <Func <Vendor, bool> > res = x => x.VendorCode == obj.VendorCode && x.CustomerId == obj.CustomerId && x.IsActive == false; var model = _vendorRepository.Get(res); if (model != null) { obj.Id = model.Id; obj.IsActive = true; _vendorRepository.Detach(model); _vendorRepository.Update(obj); return(obj.Id); } else { return(0); } } }