public async Task <TEntity> AddAsync(TEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException($"{nameof(AddAsync)} entity must not be null");
            }

            try
            {
                await _applicantContext.AddAsync(entity);

                await _applicantContext.SaveChangesAsync();

                return(entity);
            }
            catch (Exception)
            {
                throw new Exception($"{nameof(entity)} could not be saved");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Add applicant. return the custom exception if entity null. Also logs the exception if unable to save entity.
        /// </summary>
        /// <param name="entity"> take the entity as a parameter </param>
        /// <returns>Returns the created applicant</returns>
        public async Task <TEntity> AddAsync(TEntity entity)
        {
            if (entity == null)
            {
                throw new HahnException($"{nameof(AddAsync)} entity must not be null");
            }

            try
            {
                await _applicantContext.AddAsync(entity);

                await _applicantContext.SaveChangesAsync();

                return(entity);
            }
            catch (Exception exception)
            {
                _logger.LogError(exception.Message);
                throw new HahnException($"{nameof(entity)} could not be saved");
            }
        }