public bool SaveOrUpdate(Allergy allergy) { var oldItem = allergyRepository.GetAllergyByTitle(allergy.Title); if (allergy.AllergyId > 0) { if (oldItem != null && oldItem.AllergyId != allergy.AllergyId) { return(false); } allergyRepository.Update(allergy); } else { if (oldItem != null) { return(false); } allergyRepository.Add(allergy); } allergyRepository.SaveChanges(); return(true); }