예제 #1
0
 public List<model.Category> Get()
 {
     var sql = "select * from [Category]";
     var list = new List<model.Category>();
     using (var sReader = SqlDBHelper.ExecuteReader(sql))
     {
         while (sReader.Read())
         {
             var category = new model.Category();
             category.Id = sReader["Id"].ToString();
             category.Name = sReader["Name"].ToString();
             list.Add(category);
         }
     }
     return list;
 }
 //public JsonResult AddNew(Category category)
 //{
 //    category.Id = Guid.NewGuid().ToSafeTrim();
 //    var res = new BaseService().Insert<Category>(category);
 //    if (res)
 //    {
 //        return Json(new { flag = res, msg = "添加成功!" });
 //    }
 //    else {
 //        return Json(new { flag = res, msg = "添加失败!" });
 //    }
 //}
 public JsonResult Edit(Category category)
 {
     var res = false;
     if (category.Id != null && category.Id != Guid.Empty.ToSafeTrim())
         res = new BaseService().Update<Category>(category);
     else
     {
         category.Id = Guid.NewGuid().ToSafeTrim();
         res = new BaseService().Insert<Category>(category);
     }
     if (res)
     {
         return Json(new { flag = res, msg = "操作成功!" });
     }
     else
     {
         return Json(new { flag = res, msg = "操作失败!" });
     }
 }