public async Task Update(Point3DModel pointCoordinates) { var mappedEntity = ObjectMapper.Mapper.Map <Point3D>(pointCoordinates); if (mappedEntity == null) { throw new ApplicationException($"Entity could not be mapped."); } await _point3DRepository.Update(mappedEntity); _logger.LogInformation($"Entity successfully updated - {serviceName}"); }
private async Task ValidateIfExist(Point3DModel point3D) { if (point3D == null) { throw new ArgumentNullException(nameof(point3D)); } var existingEntity = await _point3DRepository.GetById(point3D.Id); if (existingEntity != null) { throw new ApplicationException($"{point3D} with this id already exists"); } }
public async Task <Point3DModel> Create(Point3DModel point3D) { await ValidateIfExist(point3D); var mappedEntity = ObjectMapper.Mapper.Map <Point3D>(point3D); if (mappedEntity == null) { throw new ApplicationException($"Entity could not be mapped."); } var newEntity = await _point3DRepository.Create(mappedEntity); _logger.LogInformation($"Entity successfully added - {serviceName}"); var newMappedEntity = ObjectMapper.Mapper.Map <Point3DModel>(newEntity); return(newMappedEntity); }