Beispiel #1
0
        public virtual async Task <object> Update(object id, IUpdateExpression <TEntity> update)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            if (update == null)
            {
                throw new ArgumentNullException(nameof(update));
            }

            var model = this.repository.Get(id);

            if (model == null)
            {
                return(null);
            }

            // TODO : Updater
            var updater = new Updater <TEntity>(update);
            await updater.Invoke(model);

            this.repository.Update(model);

            return(Task.FromResult <object>(model));
        }
        public virtual async Task <object> Update(object id, IUpdateExpression <TEntity> update)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            if (update == null)
            {
                throw new ArgumentNullException(nameof(update));
            }

            var entity = await this.Get(id, this.DbSet);

            if (entity == null)
            {
                return(null);
            }

            // TODO : Updater
            var updater = new Updater <TEntity>(update);
            await updater.Invoke(entity);

            return(await this.Update(entity));
        }
Beispiel #3
0
        public Updater(IUpdateExpression <T> updateExpression)
        {
            if (updateExpression == null)
            {
                throw new ArgumentNullException(nameof(updateExpression));
            }

            this.updateExpression = updateExpression;
        }
Beispiel #4
0
        public async Task <object> Update(object id, IUpdateExpression <IJournalMeta> update)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            if (update == null)
            {
                throw new ArgumentNullException(nameof(update));
            }

            var updateQuery = this.ConvertUpdateExpressionToMongoUpdateQuery(update);
            var filter      = this.GetFilterById(id);
            var result      = await this.Collection.UpdateOneAsync(filter, updateQuery);

            return(result);
        }
Beispiel #5
0
        protected UpdateDefinition <JournalMeta> ConvertUpdateExpressionToMongoUpdateQuery(IUpdateExpression <IJournalMeta> update)
        {
            var updateCommands = update.UpdateCommands.ToArray();

            if (updateCommands.Length < 1)
            {
                throw new ArgumentNullException(nameof(update.UpdateCommands));
            }

            var updateCommand = updateCommands[0];
            var updateQuery   = Builders <JournalMeta> .Update
                                .Set(updateCommand.FieldName, updateCommand.Value);

            for (int i = 1; i < updateCommands.Length; ++i)
            {
                updateCommand = updateCommands[i];
                updateQuery   = updateQuery.Set(updateCommand.FieldName, updateCommand.Value);
            }

            return(updateQuery);
        }
 public Task <object> Update(object id, IUpdateExpression <IHistoryItem> update)
 {
     throw new InvalidOperationException();
 }