public long Add(object obj) { var objModel = JObject.Parse(obj.ToString()); var status = objModel.ToObject <Status>(); if (IsDuplicate(status.Code, status.Id, status.Id) == false) { return(_statusRepository.Add(status)); } else { Expression <Func <Status, bool> > res = x => x.Code == status.Code && x.CustomerId == status.CustomerId && x.IsActive == false; var model = _statusRepository.Get(res); if (model != null) { status.Id = model.Id; status.IsActive = true; _statusRepository.Detach(model); _statusRepository.Update(status); return(status.Id); } else { return(0); } } }