예제 #1
0
        public JsonResult Delete(int id)
        {
            var db     = new MyDbUtil();
            var row    = db.Delete <StockItem>(id);
            var result = row > 0 ? ResultUtil.Success() : ResultUtil.Do(ResultCodes.数据库操作失败, "操作失败");

            return(Json(result));
        }
예제 #2
0
        public virtual Result Delete(T entity, Action <bool, T> action = null)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            var error = BeforeDelete(entity);

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

            var row = Db.Delete(entity);

            action?.Invoke(row > 0, entity);
            return(row > 0 ? ResultUtil.Success() : ResultUtil.Fail());
        }
예제 #3
0
        /// <summary>
        /// 删除实体
        /// </summary>
        /// <param name="entity">实体对象</param>
        /// <param name="user">操作人</param>
        /// <returns></returns>
        public virtual Result Delete(T entity, IAppUser user, Action Cb = null)
        {
            var error = ValidateDelete(entity, user);

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

            var row = db.Delete <T>(entity.Id);

            if (row > 0)
            {
                Cb?.Invoke();
                return(ResultUtil.Success());
            }
            else
            {
                return(ResultUtil.Fail());
            }
        }