Exemple #1
0
        /// <summary>
        /// 更新分类
        /// </summary>
        public string EditCategory(Category category)
        {
            string result = "更新失败";

            var conn = DBRepository.GetSqlConnection();
            try
            {
                conn.Open();
                if (category != null)
                {
                    if (!string.IsNullOrEmpty(category.Title) &&
                        !string.IsNullOrEmpty(category.Name) &&
                        category.OrderNumber > 0)
                    {
                        if (DBRepository.Update<Category>(category, "Id", conn))
                        {
                            result = "success";
                        }
                    }
                }
                else
                {
                    result = "category对象为空";
                    LogService.Log("CategoryService.EditCategory", "category对象为空");
                }
            }
            catch (Exception e)
            {
                result = "程序出现异常,详情见日志";
                LogService.Log("更新分类", e.ToString());
            }
            finally
            {
                conn.Close();
            }

            return result;
        }
Exemple #2
0
 /// <summary>
 /// 根据Id查询分类
 /// </summary>
 /// <param name="id">分类Id</param>
 /// <returns>分类对象</returns>
 public Category GetCategoryById(string id)
 {
     Category album = new Category();
     var conn = DBRepository.GetSqlConnection();
     try
     {
         conn.Open();
         album = DBRepository.SelectOne<Category>("Id='" + id + "'", conn);
     }
     catch (Exception e)
     {
         LogService.Log("查询分类", e.ToString());
     }
     finally
     {
         conn.Close();
     }
     return album;
 }