/// <summary>
        /// 获取从表单提交更新后的实体
        /// </summary>
        /// <param name="dao">数据访问对象</param>
        /// <returns>实体对象</returns>
        public virtual T GetUpdateModel(string[] excludeProperties = null, string idField = "ID")
        {
            var Id = string.Empty;

            if (this.ValueProvider.GetValue(idField) != null)
            {
                Id = this.ValueProvider.GetValue(idField).AttemptedValue;
            }
            var entity = string.IsNullOrWhiteSpace(Id) ? new T() : NH.GetSession <T>().Get <T>(Id);

            if (entity == null)
            {
                entity = new T();
            }

            try
            {
                UpdateModel(entity);
            }
            catch (InvalidOperationException ex)
            {
                var errorMsg = string.Empty;
                foreach (var item in ModelState.Values.Where(x => x.Errors.Count > 0))
                {
                    errorMsg += item.Errors.First().ErrorMessage + "。";
                }
                throw new Exception(errorMsg, ex);
            }
            return(entity);
        }
        ///// <summary>
        ///// 获取分页数据
        ///// </summary>
        ///// <param name="sql">SQL语句</param>
        ///// <param name="page">页码</param>
        ///// <param name="rows">行号</param>
        ///// <param name="filters"></param>
        ///// <param name="orders"></param>
        ///// <returns>分页数据</returns>
        //public virtual PagedResult<dynamic> getTreePagedData<TModel>(int page, int rows, string sql, List<MyFilter> filters, string orders = "", string id = "")
        //{
        //    return QueryService1.CreateTreePagedSQLQuery(page,rows,sql, filters, orders, id);
        //}

        /// <summary>
        /// 加载表单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public virtual ActionResult LoadForm(string id)
        {
            var entity = new T();

            if (!string.IsNullOrEmpty(id))
            {
                entity = NH.GetSession <T>().Get <T>(id);
            }
            return(Json(entity, JsonRequestBehavior.AllowGet));
        }
Exemple #3
0
        ///// <summary>
        ///// 获取分页数据
        ///// </summary>
        ///// <param name="sql">SQL语句</param>
        ///// <param name="page">页码</param>
        ///// <param name="rows">行号</param>
        ///// <param name="filters"></param>
        ///// <param name="orders"></param>
        ///// <returns>分页数据</returns>
        //public virtual PagedResult<dynamic> getTreePagedData<TModel>(int page, int rows, string sql, List<MyFilter> filters, string orders = "", string id = "")
        //{
        //    return QueryService1.CreateTreePagedSQLQuery(page,rows,sql, filters, orders, id);
        //}

        /// <summary>
        /// 加载表单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public virtual ActionResult LoadForm(int?id)
        {
            var entity = new T();

            if (id.HasValue)
            {
                entity = NH.GetSession <T>().Get <T>(id);
            }
            return(Json(entity, JsonRequestBehavior.AllowGet));
        }
Exemple #4
0
 /// <summary>
 /// 删除
 /// </summary>
 public virtual void Delete()
 {
     NH.GetSession(this.DatabaseName).Delete(this);
     NH.GetSession(this.DatabaseName).Flush();
 }