public bool Create(AmigoViewModel amigo, Guid usuarioId) { if (!_repositoryUsuario.ExistsWithId(usuarioId)) { throw new ApiException(ApiErrorCodes.INVUSU); } ValidationResult _result = new AmigoValidation().Validate(amigo); if (!_result.IsValid) { throw new ApiException(_result.GetErrors(), ApiErrorCodes.MODNOTVALD); } Amigo _amigo = _mapper.Map <Amigo>(amigo); _amigo.SetCreatorId(usuarioId); _repository.Create(_amigo); if (!_uow.Commit()) { throw new ApiException(ApiErrorCodes.ERROPBD); } return(true); }
public bool Edit(AmigoViewModel amigo, Guid id) { ValidationResult _result = new AmigoValidation().Validate(amigo); if (!_result.IsValid) { throw new ApiException(_result.GetErrors(), ApiErrorCodes.MODNOTVALD); } Amigo _amigo = _repository.GetById(id); if (_amigo == null) { throw new ApiException(ApiErrorCodes.INVAMIGO); } _amigo = _mapper.Map(amigo, _amigo); _repository.Update(_amigo); if (!_uow.Commit()) { throw new ApiException(ApiErrorCodes.ERROPBD); } return(true); }