public void UseSqlServer()
 {
     this._createCommand = new SqlServerCreateCommand();
     this._updateCommand = new SqlServerUpdateCommand();
     this._findCommand   = new SqlServerFindCommand();
     this._deleteCommand = new SqlServerDeleteCommand();
 }
Beispiel #2
0
        private bool ExecuteUpdate(IUpdateCommand <T> command)
        {
            var query = (WhereExpression <T>)command.Where;

            Func <T, bool> predicate;

            if (query == null)
            {
                predicate = new Func <T, bool>(m => { return(true); });
            }
            else
            {
                predicate = this.GetFilter(query.Next);
            }
            var list = this.Query().ToList();

            foreach (var item in list.Where(predicate))
            {
                foreach (var update in command.Update.Updates)
                {
                    item.TrySetValue(update.Key, update.Value);
                }
            }
            Save(list);
            return(true);
        }
Beispiel #3
0
        public async Task <bool> Handle(IUpdateCommand <T> command)
        {
            if (!command.IsValid())
            {
                return(false);
            }

            var filter         = command.FilterDefinition();
            var underStatement = command.UpdateDefinition();

            UpdateResult actionResult;

            if (command.IsManyUpdate)
            {
                actionResult = await Collection
                               .UpdateManyAsync(filter, underStatement, new UpdateOptions { IsUpsert = true });
            }
            else
            {
                actionResult = await Collection
                               .UpdateOneAsync(filter, underStatement, new UpdateOptions { IsUpsert = true });
            }

            return(actionResult.IsSuccess());
        }
Beispiel #4
0
 public T Update <T>(IUpdateCommand <T> command)
 {
     if (command.RequiresTransaction && _transaction == null)
     {
         throw new Exception($"The command {command.GetType()} requires a transaction");
     }
     return(Retry.Invoke(() => command.Execute(_connection, _transaction), _options));
 }
 public UpdateCommandTests()
 {
     sqlBuilder  = new SqlBuilder();
     sqlExecutor = new Mock <ISqlExecutorWithGeneric>();
     command     = new UpdateCommand(
         sqlBuilder: sqlBuilder,
         sqlExecutor: sqlExecutor.Object);
 }
 public ConnDataJsonVM(IUpdateCommand updateCommand, ConnectionDataJson connParameters, string title)
 {
     Debug.Assert(updateCommand != null);
     Debug.Assert(connParameters != null);
     this.connData                       = connParameters;
     this.UpdateConnectionCmd            = updateCommand;
     this.actionName                     = title;
     UpdateConnectionCmd.UpdateFinished += UpdateCommand_UpdateFinished;
 }
Beispiel #7
0
        public async Task <IActionResult> Put([FromRoute] Guid id,
                                              [FromRoute] string name,
                                              [FromRoute] string value,
                                              [FromServices] IUpdateCommand <Guid, Story> updateStoryCommand)
        {
            await updateStoryCommand.Execute(id, name, value);

            return(Ok());
        }
 public UserService(IQuery <UserData, User> query,
                    ICreateCommand <UserData> createCommand,
                    IUpdateCommand <UserData> updateCommand,
                    IDeleteCommand <UserData> deleteCommand)
 {
     _query         = query;
     _createCommand = createCommand;
     _updateCommand = updateCommand;
     _deleteCommand = deleteCommand;
 }
Beispiel #9
0
 public RoleService(IQuery <RoleData, Role> query,
                    ICreateCommand <RoleData> createCommand,
                    IUpdateCommand <RoleData> updateCommand,
                    IDeleteCommand <RoleData> deleteCommand)
 {
     _query         = query;
     _createCommand = createCommand;
     _updateCommand = updateCommand;
     _deleteCommand = deleteCommand;
 }
Beispiel #10
0
        public async Task <IActionResult> Put([FromRoute] Guid storyId,
                                              [FromRoute] int id,
                                              [FromRoute] string name,
                                              [FromRoute] string value,
                                              [FromServices] IUpdateCommand <Guid, int, Option> updateCommand)
        {
            await updateCommand.Execute(storyId, id, name, value);

            return(Ok());
        }
Beispiel #11
0
        public async Task <IActionResult> Put(
            [FromRoute] Guid storyId,
            [FromRoute] int featureId,
            [FromRoute] int optionId,
            [FromRoute] OptionValueType type,
            [FromRoute] string value,
            [FromServices] IUpdateCommand <Guid, int, int, OptionValueType, OptionValue> updateCommand)
        {
            await updateCommand.Execute(storyId, featureId, optionId, type, "Value", value);

            return(Ok());
        }
Beispiel #12
0
 private DataBase(
     ISelectCommand selectCommand,
     IInsertCommand insertCommand,
     IDeleteCommand deleteCommand,
     IUpdateCommand updateCommand,
     ISqlExecutorWithGeneric sqlExecutor)
 {
     this.selectCommand = selectCommand;
     this.insertCommand = insertCommand;
     this.deleteCommand = deleteCommand;
     this.updateCommand = updateCommand;
     this.sqlExecutor   = sqlExecutor;
 }
Beispiel #13
0
 public UpdateFeatureCommand(IUpdateCommand updateCommand)
 {
     this.updateCommand = updateCommand;
 }
Beispiel #14
0
 public UpdateOptionCommand(IUpdateCommand updateCommand)
 {
     this.updateCommand = updateCommand;
 }
Beispiel #15
0
        public void AddUpdateCommand(IUpdateCommand command)
        {
            Contract.Requires<ArgumentException>(command.CommandType != CommandType.Render);

            if (command.IsThreaded)
                command.StartThread();
            updateList.Add(command);
        }
Beispiel #16
0
 /// <summary>
 /// Add Set to query
 /// </summary>
 /// <param name="updateCommand">Update Command instance</param>
 /// <param name="column">Column name to be updated</param>
 /// <param name="value">Value to be update</param>
 /// <returns></returns>
 public static ISetOperator Set(this IUpdateCommand updateCommand, string column, DateTime value)
 => updateCommand.To <SetOperator>().Set(column, value);
 public void Handle(IUpdateCommand command)
 {
     throw new System.NotImplementedException();
 }
Beispiel #18
0
        /// <summary>
        /// Generates an update core command for the given entity, or returns null if such
        /// command cannot be generated for whatever reasons.
        /// </summary>
        internal static IUpdateCommand GenerateUpdateCommand(this IUberMap map, object entity)
        {
            if (entity == null)
            {
                return(null);
            }
            if (map == null || map.IsDisposed || !map.IsValidated)
            {
                return(null);
            }

            IUpdateCommand cmd = null;

            MetaEntity meta = MetaEntity.Locate(entity, create: true); if (meta.Record == null)
            {
                var record = new Core.Concrete.Record(map.Schema);
                map.WriteRecord(entity, record);
                meta.Record = record;
            }

            var changes = meta.GetRecordChanges(); if (changes == null)
            {
                return(null);
            }

            var num = changes.Schema.Count(x => !x.IsReadOnlyColumn);

            if (num != 0)
            {
                var id = map.ExtractId(meta.Record); if (id != null)
                {
                    cmd = map.Link.Engine.CreateUpdateCommand(map.Link, x => map.Table);
                    if (map.Discriminator != null)
                    {
                        cmd.Where(map.Discriminator);
                    }

                    var tag = new DynamicNode.Argument("x");
                    for (int i = 0; i < id.Count; i++)
                    {
                        var left = new DynamicNode.GetMember(tag, id.Schema[i].ColumnName);
                        var bin  = new DynamicNode.Binary(left, ExpressionType.Equal, id[i]);
                        cmd.Where(x => bin);
                        left.Dispose();
                        bin.Dispose();
                    }

                    for (int i = 0; i < changes.Count; i++)
                    {
                        if (changes.Schema[i].IsReadOnlyColumn)
                        {
                            continue;
                        }

                        var node = new DynamicNode.SetMember(tag, changes.Schema[i].ColumnName, changes[i]);
                        cmd.Columns(x => node);
                        node.Dispose();
                    }

                    tag.Dispose();
                    id.Dispose();
                }
            }
            changes.Dispose(disposeSchema: true);

            return(cmd);
        }
 /// <summary>
 /// Add Set to query
 /// </summary>
 /// <param name="updateCommand">Update Command instance</param>
 /// <param name="column">Column name to be updated</param>
 /// <param name="value">Value to be update</param>
 /// <returns></returns>
 public static ISetOperator Set(this IUpdateCommand updateCommand, string column, string value)
 => updateCommand is ISetOperator command?command.Set(column, value) : null;
Beispiel #20
0
 public UpdateOptionValueCommnad(IUpdateCommand updateCommand)
 {
     this.updateCommand = updateCommand;
 }
Beispiel #21
0
 public UpdateStoryCommand(OneContext oneContext, IUpdateCommand updateCommand)
 {
     this.oneContext    = oneContext;
     this.updateCommand = updateCommand;
 }