public IResult Add(Allergies entity) { var result = CheckAllergyName(entity.Name); if (!result.IsSuccess) { return(result); } _allergyRepository.Add(entity); return(new SuccessResult(Messages.AllergyAdded)); }
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); }
public IActionResult Post([FromBody] Allergy value) { value.ApplicationUser = _userRepository.GetWithDiseasesAndAllergies(User.Identity.GetUserId()); _allergyRepository.Add(value); return(Ok(value)); }