public void RelateRefugees(CreateRefugeesFamilyRelationshipInputDto createRefugeesFamilyRelationshipInputDto) { if (createRefugeesFamilyRelationshipInputDto == null) { throw new RestException(HttpStatusCode.BadRequest, Constants.Messages.MissingInputDto, new ArgumentNullException(nameof(createRefugeesFamilyRelationshipInputDto))); } if (!Enum.IsDefined(typeof(FamilyRelationshipDegree), createRefugeesFamilyRelationshipInputDto.RelationshipDegree)) { throw new RestException(HttpStatusCode.BadRequest, "The provided family relationship degree is not supported.", new ArgumentException("The value of the family relationship degree is not defined in the enumeration.")); } try { CreateRefugeesFamilyRelationshipInputDtoValidator.ValidateAndThrow(createRefugeesFamilyRelationshipInputDto); } catch (ValidationException exception) { throw new RestException(HttpStatusCode.BadRequest, exception.Message, exception); } using (IUnitOfWork unitOfWork = UnitOfWorkFactory.Create()) { unitOfWork.BeginTransaction(); RefugeeModel sourceRefugee = unitOfWork.RefugeeRepository.GetById(createRefugeesFamilyRelationshipInputDto.SourceId); if (sourceRefugee == null) { throw new RestException(HttpStatusCode.NotFound, Constants.Messages.ResourceCannotBeFound, new ArgumentException(Constants.Messages.ResourceCannotBeFound)); } RefugeeModel targetRefugee = unitOfWork.RefugeeRepository.GetById(createRefugeesFamilyRelationshipInputDto.TargetId); if (targetRefugee == null) { throw new RestException(HttpStatusCode.NotFound, Constants.Messages.ResourceCannotBeFound, new ArgumentException(Constants.Messages.ResourceCannotBeFound)); } FamilyRelationshipDegree relationshipDegree = (FamilyRelationshipDegree)createRefugeesFamilyRelationshipInputDto.RelationshipDegree; unitOfWork.RefugeeRelationshipManager.UnRelate(sourceRefugee, targetRefugee); unitOfWork.RefugeeRelationshipManager.Relate(sourceRefugee, targetRefugee, new IsFamilyRelationshipData(relationshipDegree)); unitOfWork.CommitTransaction(); } }
public IsFamilyRelationshipData(FamilyRelationshipDegree degree) { Degree = degree; }