/// <summary>
        /// 保存用户评论数据
        /// </summary>
        /// <param name="context"></param>
        public void SaveUserPosts(HttpContext context)
        {
            ZwJson zwJson = new ZwJson();
            UserPostsService userPostsService = new UserPostsService(_session);
            UserService userService = new UserService(_session);

            var postid = context.Request.Params["postid"];
            var khtml = context.Request.Params["khtml"];
            var name = context.Session["UserName"];

            if (name != null)
            {
                var data = userService.FindByName(name.ToString());
                Posts posts = new Posts() { Id = postid };
                UserPosts userPosts = new UserPosts()
                {
                    Id = Guid.NewGuid().ToString(),
                    Contents = khtml,
                    CreateDt = DateTime.Now,
                    Posts = posts,
                    User = data[0]
                };
                userPostsService.Save(userPosts);
                zwJson.IsSuccess = true;
                zwJson.JsExecuteMethod = "ajax_SaveUserPosts";
            }
            else
            {
                zwJson.IsSuccess = false;
                zwJson.Msg = "请先登录!";
            }
            context.Response.Write(_jss.Serialize(zwJson));
        }
 /// <summary>
 /// 根据课程id获取资源文件
 /// </summary>
 /// <param name="context"></param>
 public void FindByCourseId(HttpContext context)
 {
     var zwJson = new ZwJson();
     ResourcesService resourcesService = new ResourcesService(_session);
     var id = context.Request.Params["id"];
     var resources = resourcesService.FindByCourseId(new Model.Course() { Id = id });
     zwJson.Data = resources;
     zwJson.IsSuccess = true;
     zwJson.JsExecuteMethod = "Ajax_FindByCourseId";
     context.Response.Write(_jss.Serialize(zwJson));
 }
        public void GetPosts(HttpContext context)
        {
            ZwJson zwJson = new ZwJson();
            ISession session = SessionFactory.GetCurrentSession();
            PostsService posts = new PostsService(session);

            var pageStart = int.Parse(context.Request.Params["current"] ?? "1");
            var pageLimit = int.Parse(context.Request.Params["total"] ?? "10");

            var count = 0;
            var list = posts.FindByPosts(pageStart, pageLimit, ref count);
            zwJson.IsSuccess = true;
            zwJson.Data = list;
            zwJson.Other = count.ToString();
            zwJson.JsExecuteMethod = "ajax_GetPosts";
            context.Response.Write(_jss.Serialize(zwJson));
        }
        public void GetUserPostsById(HttpContext context)
        {
            ZwJson zwJson = new ZwJson();
            PostsService postsService = new PostsService(_session);
            UserPostsService userPostsService = new UserPostsService(_session);
            var postid = context.Request.Params["postid"];
            var list2 = postsService.FindById2(postid);

            list2.ReplyCount = list2.UserPostses.Count;
            zwJson.Other = list2.ReplyCount.ToString();
            postsService.SaveOrUpdate(list2);

            Posts posts = new Posts() { Id = postid };
            var list = userPostsService.FindById(posts);
            zwJson.IsSuccess = true;
            zwJson.Data = list;
            zwJson.JsExecuteMethod = "ajax_GetUserPostsById";
            context.Response.Write(_jss.Serialize(zwJson));
        }
 /// <summary>
 /// 删除数据
 /// </summary>
 /// <param name="context"></param>
 public void DelCourse(HttpContext context)
 {
     var zwJson = new ZwJson();
     CourseService courseService = new CourseService(_session);
     var id = context.Request.Params["id"];
     var idlist = id.Split('|');
     foreach (var s in idlist)
     {
         var list = courseService.GetCourse(s);
         var count = list.Resourceses.Count();
         if (count > 0)
         {
             zwJson.IsSuccess = false;
             zwJson.Msg = list.Title + "课程下有资源文件,请先删除该文件,再点击删除!";
             context.Response.Write(_jss.Serialize(zwJson));
             return;
         }
         courseService.Delete(list);
     }
     zwJson.IsSuccess = true;
     zwJson.JsExecuteMethod = "Ajax_DelCourse";
     context.Response.Write(_jss.Serialize(zwJson));
 }
 public void Login(HttpContext context)
 {
     ZwJson zwJson = new ZwJson();
     ISession session = SessionFactory.GetCurrentSession();
     UserService user = new UserService(session);
     var data = user.Exist(new User
         {
             Name = context.Request.Params["username"],
             Password = context.Request.Params["pass"]
         });
     if (data)
     {
         context.Session["UserName"] = context.Request.Params["username"];
         zwJson.IsSuccess = true;
     }
     else
     {
         zwJson.IsSuccess = false;
         zwJson.Msg = "请先注册,再登录!";
     }
     zwJson.JsExecuteMethod = "ajax_Login";
     context.Response.Write(_jss.Serialize(zwJson));
 }
 /// <summary>
 /// 删除帖子
 /// </summary>
 /// <param name="context"></param>
 public void DelPosts(HttpContext context)
 {
     ZwJson zwJson = new ZwJson();
     PostsService postsService = new PostsService(_session);
     UserService userService = new UserService(_session);
     var id = context.Request.Params["id"];
     var name = context.Session["UserName"];
     if (name != null)
     {
         postsService.Delete(new Posts
             {
                 Id = id
             });
         zwJson.IsSuccess = true;
         zwJson.JsExecuteMethod = "ajax_DelPosts";
     }
     else
     {
         zwJson.IsSuccess = false;
         zwJson.Msg = "请先登录!";
     }
     context.Response.Write(_jss.Serialize(zwJson));
 }
 /// <summary>
 /// 删除资源文件
 /// </summary>
 /// <param name="context"></param>
 public void DelRecources(HttpContext context)
 {
     ZwJson zwJson = new ZwJson();
     ResourcesService resourcesService = new ResourcesService(session);
     var name = context.Request.Params["name"];
     var courseid = context.Request.Params["courseid"];
     var type = context.Request.Params["type"];
     var pathAll = "";
     switch (type)
     {
         case "课程列表":
             pathAll = _filepath + courseid + @"\" + name;
             break;
         case "视频列表":
             pathAll = _video + courseid + @"\" + name;
             break;
         case "flashPdf":
             pathAll = _flash + courseid + @"\" + name;
             break;
     }
     try
     {
         resourcesService.DeleteByName(new Resources()
         {
             Name = name,
             Flag = type
         });
         zwJson.IsSuccess = true;
         zwJson.JsExecuteMethod = "ajax_DelRecources";
         File.Delete(pathAll);
         context.Response.Write(_jss.Serialize(zwJson));
     }
     catch (Exception)
     {
         throw;
     }
 }
        /// <summary>
        /// 根据CourseId获取数据
        /// </summary>
        /// <param name="context"></param>
        public void FindById(HttpContext context)
        {
            var zwJson = new ZwJson();
            CourseService courseService = new CourseService(_session);
            var id = context.Request.Params["id"];

            var data = courseService.GetCourse(id);
            data.ClickCount++;
            courseService.SaveOrUpdate(data);

            var course = courseService.FindById(id);
            zwJson.Data = course;
            zwJson.IsSuccess = true;
            zwJson.JsExecuteMethod = "Ajax_FindById";
            context.Response.Write(_jss.Serialize(zwJson));
        }
 /// <summary>
 /// 保存课程
 /// </summary>
 /// <param name="context"></param>
 public void SaveCourse(HttpContext context)
 {
     var zwJson = new ZwJson();
     var course = new Model.Course
         {
             Id = Guid.NewGuid().ToString(),
             Contents = context.Request.Params["content"],
             CreateDt = DateTime.Now,
             Title = context.Request.Params["title"],
             Creater = context.Session["UserName"].ToString(),
             ClickCount = 0
         };
     CourseService courseService = new CourseService(_session);
     courseService.Save(course);
     zwJson.IsSuccess = true;
     zwJson.JsExecuteMethod = "Ajax_SaveCourse";
     context.Response.Write(_jss.Serialize(zwJson));
 }
 /// <summary>
 /// 获取课程和资源
 /// </summary>
 /// <param name="context"></param>
 public void GetCourseAndResource(HttpContext context)
 {
     var zwJson = new ZwJson();
     CourseService courseService = new CourseService(_session);
     var type = context.Request.Params["type"];
     var course = courseService.GetCourseAndResource();
     zwJson.Data = from c in course
                   select new
                       {
                           c.Id,
                           c.Title,
                           Resourceses = c.Resourceses.Where(s => s.Flag == type)
                       };
     zwJson.IsSuccess = true;
     zwJson.JsExecuteMethod = "Ajax_GetCourseAndResource";
     context.Response.Write(_jss.Serialize(zwJson));
 }
 /// <summary>
 /// 获取课程列表
 /// </summary>
 /// <param name="context"></param>
 public void GetCourse(HttpContext context)
 {
     var zwJson = new ZwJson();
     CourseService courseService = new CourseService(_session);
     var list = courseService.GetView();
     zwJson.Data = list;
     zwJson.IsSuccess = true;
     zwJson.JsExecuteMethod = "HtmlCourse";
     context.Response.Write(_jss.Serialize(zwJson));
 }
 public void Register(HttpContext context)
 {
     ZwJson zwJson=new ZwJson();
     ISession session = SessionFactory.GetCurrentSession();
     UserService user = new UserService(session);
     context.Session["UserName"] = context.Request.Params["username"];
     user.Save(new User() {
         Id = Guid.NewGuid().ToString(),
         CreateDt = DateTime.Now,
         Name = context.Request.Params["username"],
         Password = context.Request.Params["pass"],
         Sex = context.Request.Params["sex"],
         BriefIntroduction = context.Request.Params["introduction"]
     });
     zwJson.IsSuccess = true;
     zwJson.JsExecuteMethod = "ajax_SaveUser";
     context.Response.Write(_jss.Serialize(zwJson));
 }
 public void Quit(HttpContext context)
 {
     ZwJson zwJson = new ZwJson();
     context.Session["UserName"] = null;
     zwJson.IsSuccess = true;
     zwJson.JsExecuteMethod = "ajax_Quit";
     context.Response.Write(_jss.Serialize(zwJson));
 }
 /// <summary>
 /// 保存课程资源文件
 /// </summary>
 /// <param name="context"></param>
 public void SaveFile(HttpContext context)
 {
     ZwJson zwJson = new ZwJson();
     ResourcesService resourcesService = new ResourcesService(session);
     HttpPostedFile file = context.Request.Files["Filedata"];
     var courseid = context.Request.Params["id"];
     var type = context.Request.Params["type"];
     Resources resources = new Resources();
     if (file == null) return;
     var pathAll = "";
     var httppath = "";
     var pathDirectory = "";
     switch (type)
     {
         case "课程列表":
             pathAll = _filepath + courseid + @"\" + file.FileName;
             httppath = "/CourseFile/" + courseid + @"\" + file.FileName;
             pathDirectory = _filepath + courseid;
             break;
         case "视频列表":
             pathAll = _video + courseid + @"\" + file.FileName;
             httppath = "/OlFile/" + courseid + @"\" + file.FileName;
             pathDirectory = _video + courseid;
             break;
         case "flashPdf":
             pathAll = _flash + courseid + @"\" + file.FileName;
             httppath = "/FlashFile/" + courseid + @"\" + file.FileName;
             pathDirectory = _flash + courseid;
             break;
     }
     var url = UrlHelper.Resolve(httppath);
     int size = file.ContentLength / 1024;
     var flag = file.ContentLength % 1024;
     if (flag > 0)
     {
         size++;
     }
     resources.FileSize = size.ToString(CultureInfo.InvariantCulture);
     resources.Flag = type;
     resources.Name = file.FileName;
     resources.FileType = file.FileName.Split('.')[file.FileName.Split('.').Length - 1];
     resources.FilePath = url;
     resources.CreateDt = DateTime.Now;
     resources.Course = new Model.Course()
     {
         Id = courseid
     };
     if (!Directory.Exists(pathDirectory))
     {
         Directory.CreateDirectory(pathDirectory);
     }
     if (File.Exists(pathAll))
     {
         resourcesService.DeleteByName(resources);
     }
     resources.Id = Guid.NewGuid().ToString();
     resourcesService.Save(resources);
     file.SaveAs(pathAll);
     //zwJson.IsSuccess = true;
     //zwJson.JsExecuteMethod = "ajax_SaveFile";
     //context.Response.Write(_jss.Serialize(zwJson));
 }