Example #1
0
        public async Task <TEntity> UpdateAsync(TEntity updated)
        {
            try
            {
                if (updated == null)
                {
                    return(null);
                }

                var existing = await _context.Set <TEntity>().FindAsync(updated.CommentKey);

                if (existing != null)
                {
                    _context.Entry(existing).CurrentValues.SetValues(updated);
                    await _context.SaveChangesAsync();
                }

                else
                {
                    throw new CommandServiceException($"Missing entity {updated.CommentKey}");
                }

                return(existing);
            }

            catch (Exception ex)
            {
                SaveError(ex);
                return(null);
            }
        }
Example #2
0
 public void Update(T entity)
 {
     _dbContext.Entry(entity).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
 }