/// <summary>
        /// 新建数据实体
        /// </summary>
        /// <param name="entity">要新建的数据实体</param>
        /// <returns>返回新建的数据实体</returns>
        public WebApiResult<Product_ProductContract> Add(Product_ProductContract entity)
        {
            var result = new WebApiResult<Product_ProductContract>();

            #region 验证
            if (Validate(result, entity))
            {
                if (DataContext.Product_ProductContract.Any(x => x.Deleted == false && x.Name == entity.Name))
                {
                    result.AddError(string.Format("名称 '{0}' 已经存在。", entity.Name));
                }
            }
            #endregion

            #region 保存
            if (result.Success)
            {
                var maxSortOrder = 0;
                if (DataContext.Product_ProductContract.Any())
                {

                    maxSortOrder = DataContext.Product_ProductContract.Max(x => x.SortOrder);
                }
                entity.SortOrder = maxSortOrder + 1;
                entity.Id = Guid.NewGuid();
                entity.CreatedAt = DateTime.Now;
                entity.UpdatedAt = DateTime.Now;
                // entity.Deleted = false;
                DataContext.Product_ProductContract.Add(entity);

                DataContext.SaveChanges();

                result.Data = entity;
            }
            #endregion

            return result;
        }
 /// <summary>
 /// 验证数据实体
 /// </summary>
 /// <param name="result">result 参数</param>
 /// <param name="entity">要验证的数据实体</param>
 /// <returns>成功返回 true;否则返回 false。</returns>
 protected bool Validate(WebApiResult<Product_ProductContract> result, Product_ProductContract entity)
 {
     if (string.IsNullOrWhiteSpace(entity.Name))
     {
         result.AddError("请输入参数合同名称。");
     }
     if (string.IsNullOrWhiteSpace(entity.TemplateHtml.ToString()))
     {
         result.AddError("请输入参数合同内容。");
     }
     return result.Success;
 }
        /// <summary>
        /// 更新数据实体
        /// </summary>
        /// <param name="entity">要更新的数据实体</param>
        /// <returns>返回更新后的数据实体</returns>
        public virtual WebApiResult<Product_ProductContract> Update(Product_ProductContract entity)
        {
            var result = new WebApiResult<Product_ProductContract>();

            #region 验证
            if (Validate(result, entity))
            {
                if (DataContext.Product_ProductContract.Any(x => x.Deleted == false
                    && x.Id != entity.Id
                    && x.Name == entity.Name))
                {
                    result.AddError(string.Format("名称 '{0}' 已经存在。", entity.Name));
                }
            }
            #endregion

            #region 保存
            if (result.Success)
            {
                var origin = DataContext.Product_ProductContract.FirstOrDefault(x => x.Id == entity.Id);
                if (origin != null)
                {
                    origin.Name = entity.Name;
                    origin.TemplateHtml = entity.TemplateHtml;
                    entity.UpdatedAt = DateTime.Now;
                    DataContext.SaveChanges();

                    result.Data = origin;
                }
            }
            #endregion

            return result;
        }