Example #1
0
        public UserIndex EditUserIndex(User user, bool autoSave = true)
        {
            if (user == null)
            {
                return(new UserIndex());
            }
            var ui = dbContext.connection.Query <UserIndex>(u => user.Id.Equals(u.UserId)).FirstOrDefault();

            if (ui == null)
            {
                return(null);
            }
            var currui = Mapper.Map <UserIndex>(user);

            ui.DepartmentId = currui.DepartmentId;
            ui.Password     = currui.Password;
            ui.UserName     = currui.UserName;

            var statement = StatementFactory.Update <UserIndex>(Dialect.MySQL);

            dbContext.connection.Execute(statement, EntityToValue <UserIndex>(ui));
            if (autoSave)
            {
                Save();
            }

            return(ui);
        }
Example #2
0
        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="entity">实体</param>
        /// <param name="autoSave">是否立即执行保存</param>
        public override TEntity Update(TEntity entity, bool autoSave = true)
        {
            var obj       = Get(entity.Id);
            var statement = StatementFactory.Update <TEntity>(Dialect.MySQL);

            _dbContext.connection.Execute(statement, EntityToValue <TEntity>(obj));
            if (autoSave)
            {
                Save();
            }
            return(entity);
        }
Example #3
0
 public virtual Task <bool> UpdateAsync(T obj) => GeneratedNonQueryAsync(StatementFactory
                                                                         .Update <T>()
                                                                         .WhereId(obj)
                                                                         .Build(obj));