コード例 #1
0
ファイル: CourseBll.cs プロジェクト: QJesus/ASP.Net-MVC
 public void DeleteCourse(long courseId)
 {
     // 校验参数
     Course course = new CourseBll(new HengNuoWangDBContext()).GetCourse(courseId);
     if (course == null)
     {
         string.Format("不存在指定courseId:{0}的课程", courseId).ThrowException();
     }
     // 删除课程
     int row = _dal.DeleteCourse(course.Id);
     // 判断返回值
     if (row <= 0)
     {
         string.Format("删除课程courseId:{0}失败", course.Id).ThrowException();
     }
     if (row > 1)
     {
         string.Format("删除{0}个相同课程courseId:{1}", row, course.Id).ThrowException();
     }
 }
コード例 #2
0
 public JsonResult Edit(long id)
 {
     // 检查请求
     Course oldCourse = new CourseBll(new HengNuoWangDBContext()).GetCourse(id);
     if (oldCourse == null)
     {
         return JsonHelper.GetJsonResult(_ERROR, "课程不存在");
     }
     string courseName = Request["name"];
     short coursePrice;
     if (CommonHelper.IsNullOrEmptyOrWhiteSpace(courseName) ||
         courseName.Length > 50 ||
         !short.TryParse(Request["price"], out coursePrice) ||
         coursePrice < 0)
     {
         return JsonHelper.GetJsonResult(_ERROR, "课程名 或 价格 错误");
     }
     // 更新
     Course newCourse = new Course()
     {
         Id = oldCourse.Id,
         Name = courseName,
         Price = coursePrice,
     };
     if (oldCourse.Name == newCourse.Name && oldCourse.Price == newCourse.Price)
     {
         return JsonHelper.GetJsonResult(_ERROR, "课程名或价格至少修改一个");
     }
     _courseBll.UpdateCourse(newCourse);
     // 记录日志
     string log = string.Format("修改课程{4}:名称【{0}=>{1}】;价格【{2}=>{3}】",
         oldCourse.Name, newCourse.Name, oldCourse.Price, newCourse.Price, newCourse.Id);
     AdminOperationLogBll.AddAdminOperationLog(AdminUserId, log);
     return JsonHelper.GetJsonResult(_OK, "更新成功", "/Course/List");
 }
コード例 #3
0
ファイル: CourseBll.cs プロジェクト: QJesus/ASP.Net-MVC
 public void UpdateCourse(Course course)
 {
     // 检查参数
     if (course == null)
     {
         throw new ArgumentNullException("course");
     }
     Course crs = new CourseBll(new HengNuoWangDBContext()).GetCourse(course.Id);
     if (crs == null)
     {
         string.Format("不存在指定courseId:{0}的课程", course.Id).ThrowException();
     }
     // 更新课程
     int row = _dal.UpdateCourse(course);
     // 判断返回值
     if (row <= 0)
     {
         string.Format("更新课程:{0}失败", course.Name).ThrowException();
     }
     if (row > 1)
     {
         string.Format("更新{0}个相同课程:{1}", row, course.Name).ThrowException();
     }
 }