예제 #1
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public Result <int> Update(Account entity, IAppUser user)
        {
            try
            {
                var error = Validate(entity);
                if (!string.IsNullOrWhiteSpace(error))
                {
                    return(ResultUtil.Do(ResultCodes.验证失败, 0, error));
                }

                entity.BeforeUpdate(user);
                var row = _db.Update(entity);
                if (row <= 0)
                {
                    return(ResultUtil.Do(ResultCodes.数据库操作失败, 0, "数据写入失败"));
                }
                _db.Execute(@"UPDATE [Asset_Asset] SET DeptId=@DeptId WHERE AccountId=@AccountId",
                            new { AccountId = entity.Id, DeptId = entity.DeptId });
                return(ResultUtil.Success(entity.Id));
            }
            catch (Exception ex)
            {
                return(ResultUtil.Exception(ex, 0));
            }
        }
예제 #2
0
        public virtual Result Update(T entity, BaseAppUser user, Action <bool, T> action = null)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }
            if (entity.Id <= 0)
            {
                throw new ArgumentException("实体ID无效,必须大于0", nameof(entity));
            }
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user), "可跟踪实体必须提供操作人信息");
            }

            entity.BeforeUpdate(user);

            var error = BeforeUpdate(entity, user);

            if (!string.IsNullOrWhiteSpace(error))
            {
                return(ResultUtil.AuthFail(error));
            }

            var row     = Db.Update(entity);
            var success = row > 0;

            action?.Invoke(success, entity);
            return(success ? ResultUtil.Success() : ResultUtil.Fail());
        }
예제 #3
0
        public Result <int> Update(Dept dept, IAppUser user)
        {
            try
            {
                var error = Validate(dept);
                if (!string.IsNullOrWhiteSpace(error))
                {
                    return(ResultUtil.Do(ResultCodes.验证失败, 0, error));
                }

                if (dept.ParentId == dept.Id)
                {
                    return(ResultUtil.Do(ResultCodes.验证失败, 0, "不能将自身设置为上级"));
                }

                dept.BeforeUpdate(user);
                var row = _db.Update(dept);
                if (row <= 0)
                {
                    return(ResultUtil.Do(ResultCodes.数据库操作失败, 0, "数据写入失败"));
                }

                DeptUtil.Clear();
                return(ResultUtil.Success(dept.Id));
            }
            catch (Exception ex)
            {
                return(ResultUtil.Exception(ex, 0));
            }
        }
예제 #4
0
        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="entity">实体对象</param>
        /// <param name="user">操作人</param>
        /// <returns></returns>
        public virtual Result Update(T entity, AppUser user, Action Cb = null)
        {
            var error = ValidateUpdate(entity, user);

            if (!string.IsNullOrWhiteSpace(error))
            {
                return(ResultUtil.AuthFail(error));
            }
            entity.BeforeUpdate(user);
            var row = db.Update <T>(entity);

            if (row > 0)
            {
                Cb?.Invoke();
                return(ResultUtil.Success());
            }
            else
            {
                return(ResultUtil.Fail());
            }
        }
예제 #5
0
        public Result <int> Update(User u, IAppUser user)
        {
            var error = Validate(u);

            if (!string.IsNullOrWhiteSpace(error))
            {
                return(ResultUtil.Do(ResultCodes.验证失败, 0, error));
            }

            u.Version = Guid.NewGuid().ToString("N");
            u.BeforeUpdate(user);
            var id = _db.Update(u);

            return(id > 0 ? ResultUtil.Success(u.Id) : ResultUtil.Do(ResultCodes.数据库操作失败, 0));
        }
예제 #6
0
        public Result <int> Update(T t, IAppUser user)
        {
            try
            {
                var error = ValidUpdate(t, user);
                if (!string.IsNullOrWhiteSpace(error))
                {
                    return(ResultUtil.Do(ResultCodes.验证失败, 0, error));
                }

                t.BeforeUpdate(user);
                var row = db.Update(t);
                return(row > 0 ? ResultUtil.Success(t.Id) : ResultUtil.Do(ResultCodes.数据库操作失败, 0, "数据写入失败"));
            }
            catch (Exception ex)
            {
                return(ResultUtil.Exception(ex, 0));
            }
        }
예제 #7
0
        public virtual Result Update(T entity, Action <bool, T> action = null)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }
            if (entity.Id <= 0)
            {
                throw new ArgumentException("实体ID无效,必须大于0", nameof(entity));
            }

            var error = BeforeUpdate(entity);

            if (!string.IsNullOrWhiteSpace(error))
            {
                return(ResultUtil.AuthFail(error));
            }

            var row = Db.Update(entity);

            action?.Invoke(row > 0, entity);
            return(row > 0 ? ResultUtil.Success() : ResultUtil.Fail());
        }
예제 #8
0
        public Result <int> Update(AssetCate cate, IAppUser user)
        {
            try
            {
                var error = Validate(cate);
                if (!string.IsNullOrWhiteSpace(error))
                {
                    return(ResultUtil.Do(ResultCodes.验证失败, 0, error));
                }

                if (cate.ParentId == cate.Id)
                {
                    return(ResultUtil.Do(ResultCodes.验证失败, 0, "不能将自身设置为上级"));
                }

                var children = AssetCateUtil.GetSelfAndChildrenIds(cate.Id);
                if (children.Contains(cate.ParentId))
                {
                    return(ResultUtil.Do(ResultCodes.验证失败, 0, "不能将上级分类指定为其下属"));
                }

                cate.BeforeUpdate(user);
                var row = _db.Update(cate);
                if (row > 0)
                {
                    AssetCateUtil.Clear();
                    return(ResultUtil.Success(cate.Id));
                }

                return(ResultUtil.Do(ResultCodes.数据库操作失败, 0, "数据写入失败"));
            }
            catch (Exception ex)
            {
                return(ResultUtil.Exception(ex, 0));
            }
        }