예제 #1
0
        /// <summary>
        /// Updates the specified entity in the backing store, as an asynchronous operation.
        /// </summary>
        /// <param name="entity">The entity to be updated.</param>
        /// <returns>
        /// The System.Threading.Tasks.Task that represents the asynchronous operation.
        /// </returns>
        public async Task UpdateAsync(TEntity entity)
        {
            CoreValidator.ThrowIfInvalidState(entity);

            var exist = await this.GetAsync(entity.Id) != null;

            if (!exist)
            {
                throw new InvalidOperationException(
                          $"{entity.GetType().Name} does not exist!");
            }

            await this.dbContext.SaveAsync(entity);
        }
예제 #2
0
        /// <summary>
        /// Adds the specified entity in the backing store, as an asynchronous operation.
        /// </summary>
        /// <param name="entity">The entity to be added.</param>
        /// <returns>
        /// The System.Threading.Tasks.Task that represents the asynchronous operation.
        /// </returns>
        public async Task AddAsync(TEntity entity)
        {
            CoreValidator.ThrowIfInvalidState(entity);

            await this.dbContext.SaveAsync(entity);
        }