/// <summary> /// 根据查看数量获取文章 /// </summary> /// <returns></returns> public List <ContentModel> GetContentBySee() { try { using (qds105749277_dbEntities db = new qds105749277_dbEntities()) { var sql = from a in db.Content join b in db.Type on a.typeId equals b.typeId join c in db.Label on a.LabelId equals c.Id orderby a.See descending select new ContentModel() { Author = a.Author, CommentNum = a.CommentNum, CreateTime = a.CreateTime, Id = a.Id, ImagePath = a.ImagePath, LabelId = a.LabelId, See = a.See, //Text = a.Text, Describe = a.Describe, Title = a.Title, typeId = a.typeId, TypeNAme = b.TypeName, LabelName = c.LabelName }; var list = sql.Take(7).ToList(); return(list); } } catch (Exception) { throw; } }
/// <summary> /// 添加文章 /// </summary> /// <param name="model"></param> /// <returns></returns> public int AddContent(ContentModel model) { try { using (qds105749277_dbEntities db = new qds105749277_dbEntities()) { Content c = new Content() { Author = model.Author, CommentNum = model.CommentNum, CreateTime = model.CreateTime, ImagePath = model.ImagePath, LabelId = model.LabelId, typeId = model.typeId, See = model.See, Text = model.Text, Describe = model.Describe, Title = model.Title }; db.Content.Add(c); int res = db.SaveChanges(); if (res > 0) { res = c.Id; } return(res); } } catch (Exception) { throw; } }
/// <summary> /// 根据ID获取文章 /// </summary> /// <param name="cid"></param> /// <returns></returns> public ContentModel GetContentById(int cid) { try { using (qds105749277_dbEntities db = new qds105749277_dbEntities()) { var sql = (from a in db.Content join b in db.Type on a.typeId equals b.typeId join c in db.Label on a.LabelId equals c.Id where a.Id == cid select new ContentModel() { Author = a.Author, Id = a.Id, See = a.See, CommentNum = a.CommentNum, CreateTime = a.CreateTime, ImagePath = a.ImagePath, Text = a.Text, Title = a.Title, TypeNAme = b.TypeName, LabelName = c.LabelName }).FirstOrDefault(); return(sql); } } catch (Exception) { throw; } }
/// <summary> /// 获取评论列表 /// </summary> /// <param name="cid"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <returns></returns> public ContentPageModel <CommentModel> GetComment(int cid, int pageIndex, int pageSize) { try { using (qds105749277_dbEntities db = new qds105749277_dbEntities()) { ContentPageModel <CommentModel> model = new ContentPageModel <CommentModel>(); var sql = from a in db.Comment join b in db.Users on a.UserId equals b.Id where a.ContentId == cid orderby a.Time descending select new CommentModel() { ContentId = a.ContentId, Id = a.Id, Text = a.Text, Time = a.Time, UserId = a.UserId, UserName = b.UserName, ZhiChi = a.ZhiChi, FanDui = a.FanDui }; var list = sql.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(); model.cList = list; model.Count = sql.Count(); return(model); } } catch (Exception) { throw; } }
/// <summary> /// 获取类别 /// </summary> /// <param name="search"></param> /// <param name="index"></param> /// <param name="page"></param> /// <param name="total"></param> /// <returns></returns> public TableModel <TypeModel> GetTypes(string search, int index, int page, int total) { try { using (qds105749277_dbEntities db = new qds105749277_dbEntities()) { var sql = from a in db.Type where a.TypeName.Contains(search) orderby a.typeId descending select new TypeModel() { typeId = a.typeId, TypeName = a.TypeName }; TableModel <TypeModel> table = new TableModel <TypeModel>(index, total, sql, true); var list = sql.Skip(index * page - page).Take(page).ToList(); table.Lst = list; return(table); } } catch (Exception) { throw; } }
/// <summary> /// 修改方法 /// </summary> /// <param name="model"></param> /// <returns></returns> public int UpdateContent(ContentModel model) { try { using (qds105749277_dbEntities db = new qds105749277_dbEntities()) { Content con = db.Content.Where(c => c.Id == model.Id).FirstOrDefault(); if (con != null) { con.ImagePath = model.ImagePath; con.LabelId = model.LabelId; con.Text = model.Text; con.typeId = model.typeId; con.Author = model.Author; con.Title = model.Title; db.SaveChanges(); return(con.Id); } else { return(0); } } } catch (Exception) { throw; } }
public ContentModel GetContentById(int id) { try { using (qds105749277_dbEntities db = new qds105749277_dbEntities()) { var sql = from a in db.Content where a.Id == id select new ContentModel() { Id = a.Id, Title = a.Title, See = a.See, Author = a.Author, CommentNum = a.CommentNum, CreateTime = a.CreateTime, Describe = a.Describe, ImagePath = a.ImagePath, LabelId = a.LabelId, typeId = a.typeId, Text = a.Text }; return(sql.FirstOrDefault()); } } catch (Exception) { throw; } }
/// <summary> /// 用户评论 /// </summary> /// <param name="model"></param> /// <returns></returns> public int PingLunTiTiao(Mldel.Contents.CommentModel model) { try { using (TransactionScope scope = new TransactionScope()) { using (qds105749277_dbEntities db = new qds105749277_dbEntities()) { var sql1 = db.Comment.Where(c => c.ContentId == model.ContentId).ToList(); int louceng = 1; if (sql1.Count > 0) { if (sql1.Count == 1) { louceng++; } else if (sql1.Count == 2) { louceng += 2; } else if (sql1.Count == 3) { louceng += 3; } else { louceng = (int)sql1[sql1.Count - 1].LouCeng + louceng; } } Comment cm = new Comment() { Text = model.Text, ContentId = model.ContentId, Time = model.Time, UserId = model.UserId, ZhiChi = model.ZhiChi, FanDui = model.FanDui, LouCeng = louceng }; //文章表的评论字段加一 var sql = db.Content.Where(c => c.Id == model.ContentId).FirstOrDefault(); if (sql != null) { sql.CommentNum += 1; } db.Comment.Add(cm); int res = db.SaveChanges(); scope.Complete(); return(res); } } } catch (Exception) { throw; } }
/// <summary> /// 获取总注册人数 /// </summary> /// <returns></returns> public int GetUserCount() { try { using (qds105749277_dbEntities db = new qds105749277_dbEntities()) { return(db.Users.Count()); } } catch (Exception) { throw; } }
/// <summary> /// 获取类别 /// </summary> /// <returns></returns> public List <TypeModel> GetTyleList() { try { using (qds105749277_dbEntities db = new qds105749277_dbEntities()) { var sql = db.Type.Select(t => new TypeModel() { typeId = t.typeId, TypeName = t.TypeName }).ToList(); return(sql); } } catch (Exception) { throw; } }
public AdminUserModel LoginAdmin(string username, string pwd) { try { using (qds105749277_dbEntities db = new qds105749277_dbEntities()) { var sql = db.AdminUser.Where(u => u.UserName == username && u.UserPwd == pwd).Select(u => new AdminUserModel() { Id = u.Id, UserName = u.UserName, UserPwd = u.UserPwd }).FirstOrDefault(); return(sql); } } catch (Exception) { throw; } }
/// <summary> /// 检测用户是否存在 /// </summary> /// <param name="username"></param> /// <returns></returns> public bool CheckUser(string username) { try { using (qds105749277_dbEntities db = new qds105749277_dbEntities()) { var sql = db.Users.Where(u => u.UserName == username).FirstOrDefault(); if (sql != null) { return(true); } return(false); } } catch (Exception) { throw; } }
/// <summary> /// 修改标签 /// </summary> /// <param name="id"></param> /// <param name="name"></param> /// <returns></returns> public int UpdateLabel(int id, string name) { try { using (qds105749277_dbEntities db = new qds105749277_dbEntities()) { var label = db.Label.Where(l => l.Id == id).FirstOrDefault(); if (label != null) { label.LabelName = name; } return(db.SaveChanges()); } } catch (Exception) { throw; } }
/// <summary> /// 新增类别 /// </summary> /// <param name="name"></param> /// <returns></returns> public int AddType(string name) { try { using (qds105749277_dbEntities db = new qds105749277_dbEntities()) { DB.Type t = new DB.Type() { TypeName = name }; db.Type.Add(t); return(db.SaveChanges()); } } catch (Exception) { throw; } }
/// <summary> /// 新增标签 /// </summary> /// <param name="name"></param> /// <returns></returns> public int AddLabel(string name) { try { using (qds105749277_dbEntities db = new qds105749277_dbEntities()) { Label l = new Label() { LabelName = name }; db.Label.Add(l); return(db.SaveChanges()); } } catch (Exception) { throw; } }
/// <summary> /// 用户注册 /// </summary> /// <param name="regusername"></param> /// <param name="regpassword"></param> /// <returns></returns> public int Reg(string regusername, string regpassword) { try { using (qds105749277_dbEntities db = new qds105749277_dbEntities()) { Users u = new Users() { Email = regusername, Pwd = regpassword, NickName = regusername, UserName = regusername, UserImg = "/images/userImg/default.jpg" }; db.Users.Add(u); return(db.SaveChanges()); } } catch (Exception) { throw; } }
/// <summary> /// 删除文章 /// </summary> /// <param name="id"></param> /// <returns></returns> public int DeleteContent(int id) { try { using (qds105749277_dbEntities db = new qds105749277_dbEntities()) { var sql = db.Content.Where(c => c.Id == id).FirstOrDefault(); if (sql != null) { db.Content.Remove(sql); } return(db.SaveChanges()); } } catch (Exception) { throw; } }
/// <summary> /// 根据文章类型获取文章列表 /// </summary> /// <param name="typeId"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <returns></returns> public ContentPageModel <ContentModel> GetContentListByType(int typeId, int pageIndex, int pageSize) { try { using (qds105749277_dbEntities db = new qds105749277_dbEntities()) { ContentPageModel <ContentModel> model = new ContentPageModel <ContentModel>(); var sql = from a in db.Content join b in db.Type on a.typeId equals b.typeId join c in db.Label on a.LabelId equals c.Id where a.typeId == typeId orderby a.See descending select new ContentModel() { Author = a.Author, CommentNum = a.CommentNum, CreateTime = a.CreateTime, Id = a.Id, ImagePath = a.ImagePath, LabelId = a.LabelId, See = a.See, //Text = a.Text, Describe = a.Describe, Title = a.Title, typeId = a.typeId, TypeNAme = b.TypeName, LabelName = c.LabelName }; var list = sql.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(); model.cList = list; int count = sql.Count(); model.Count = count; model.pageCount = Convert.ToInt32(Math.Ceiling((double)count / (double)pageSize)); return(model); } } catch (Exception) { throw; } }
public int AddSee(int cid) { try { using (qds105749277_dbEntities db = new qds105749277_dbEntities()) { var sql = db.Content.Where(c => c.Id == cid).FirstOrDefault(); if (sql != null) { sql.See += 1; return(db.SaveChanges()); } return(0); } } catch (Exception) { throw; } }
/// <summary> /// 增加评论反对数 /// </summary> /// <param name="commentId"></param> /// <returns></returns> public int FanDui(int commentId, int userId) { try { //事务处理 using (TransactionScope scope = new TransactionScope()) { using (qds105749277_dbEntities db = new qds105749277_dbEntities()) { //判断是否已经支持或者反对过这条评论 var sql1 = db.ZhiChiFanDui.Where(z => z.CommentId == commentId && z.UserId == userId).FirstOrDefault(); if (sql1 == null) { int num = 0; //判断评论是否存在,存在则反对数加1 var sql = db.Comment.Where(c => c.Id == commentId).FirstOrDefault(); if (sql != null) { sql.FanDui += 1; num = (int)sql.FanDui; //对这条评论支持过后要新增一条支持反对的记录 ZhiChiFanDui z = new ZhiChiFanDui() { CommentId = commentId, UserId = userId, ZhiOrFanDui = 0 }; db.ZhiChiFanDui.Add(z); db.SaveChanges(); //事务提交 scope.Complete(); return(num); } } return(0); } } } catch (Exception) { throw; } }
/// <summary> /// 获取文章类别 /// </summary> /// <param name="search"></param> /// <param name="index"></param> /// <param name="page"></param> /// <param name="total"></param> /// <param name="typeId"></param> /// <returns></returns> public TableModel <ContentModel> GetContentList(string search, int index, int page, int total, int typeId) { try { using (qds105749277_dbEntities db = new qds105749277_dbEntities()) { var sql = from a in db.Content join b in db.Label on a.LabelId equals b.Id join c in db.Type on a.typeId equals c.typeId where (a.Title.Contains(search) || a.Text.Contains(search)) orderby a.CreateTime descending select new ContentModel() { Id = a.Id, Title = a.Title, See = a.See, Author = a.Author, CommentNum = a.CommentNum, CreateTime = a.CreateTime, Describe = a.Describe, ImagePath = a.ImagePath, LabelId = a.LabelId, typeId = a.typeId, TypeNAme = c.TypeName, LabelName = b.LabelName }; if (typeId != 0) { sql = sql.Where(s => s.typeId == typeId); } TableModel <ContentModel> tableInfo = new TableModel <ContentModel>(index, total, sql, true); var list = sql.Skip(index * page - page).Take(page).ToList(); tableInfo.Lst = list; return(tableInfo); } } catch (Exception) { throw; } }
/// <summary> /// 获取文章类型 /// </summary> /// <returns></returns> public List <Mldel.Contents.TypeModel> GetTypes() { try { using (qds105749277_dbEntities db = new qds105749277_dbEntities()) { var sql = from a in db.Type select new TypeModel() { typeId = a.typeId, TypeName = a.TypeName }; var list = sql.ToList(); return(list); } } catch (Exception) { throw; } }
public bool CheckType(string name) { try { using (qds105749277_dbEntities db = new qds105749277_dbEntities()) { var sql = from a in db.Type where a.TypeName == name select a; if (sql.FirstOrDefault() != null) { return(true); } return(false); } } catch (Exception) { throw; } }
/// <summary> /// 获取为文章标签 /// </summary> /// <returns></returns> public List <Mldel.Contents.LabelModel> GetLabel() { try { using (qds105749277_dbEntities db = new qds105749277_dbEntities()) { var sql = from a in db.Label orderby a.Id select new LabelModel() { Id = a.Id, LabelName = a.LabelName }; var list = sql.Take(9).ToList(); return(list); } } catch (Exception) { throw; } }
public List <ContentModel> GetContentList(string search, int pageIndex, int pageSize, int ContenttypeId, out int count) { try { using (qds105749277_dbEntities db = new qds105749277_dbEntities()) { var sql = from a in db.Content join b in db.Label on a.LabelId equals b.Id join c in db.Type on a.typeId equals c.typeId where a.typeId == ContenttypeId select new ContentModel() { Author = a.Author, Describe = a.Describe, See = a.See, CommentNum = a.CommentNum, CreateTime = a.CreateTime, Id = a.Id, LabelId = a.LabelId, LabelName = b.LabelName, Title = a.Title, TypeNAme = c.TypeName }; if (!string.IsNullOrEmpty(search)) { sql = sql.Where(s => s.Title.Contains(search) || s.Describe.Contains(search)); } count = sql.Count(); var list = sql.OrderByDescending(s => s.CreateTime).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(); return(list); } } catch (Exception) { throw; } }
/// <summary> /// 登录 /// </summary> /// <param name="username"></param> /// <param name="pwd"></param> /// <returns></returns> public UserModel Login(string username, string pwd) { try { using (qds105749277_dbEntities db = new qds105749277_dbEntities()) { var sql = (from a in db.Users where a.UserName == username && a.Pwd == pwd select new UserModel() { Id = a.Id, Email = a.Email, Pwd = a.Pwd, NickName = a.NickName, UserName = a.UserName }).FirstOrDefault(); return(sql); } } catch (Exception) { throw; } }
/// <summary> /// 获取评论数据 /// </summary> /// <param name="cid"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <returns></returns> public Mldel.Contents.ContentPageModel <Mldel.Contents.CommentModel> GetCommentPageList(int cid, int pageIndex, int pageSize, int userId) { try { using (qds105749277_dbEntities db = new qds105749277_dbEntities()) { ContentPageModel <CommentModel> model = new ContentPageModel <CommentModel>(); var sql = from a in db.Comment join b in db.Users on a.UserId equals b.Id where a.ContentId == cid orderby a.LouCeng select new CommentModel() { //UserId指的是回复的那个用户的 //HuiFuUserId指的是被回复的用户 ContentId = a.ContentId, Id = a.Id, Text = a.Text, Time = a.Time, UserId = a.UserId, UserName = b.UserName, FanDui = a.FanDui, ZhiChi = a.ZhiChi, LouCeng = a.LouCeng, UserImg = b.UserImg //var customers = DB.Customer.Join(DB.Commission, cst => cst.CommissionId, // com => com.CommissionId, (cst, com) => new Customer() // { // CommissionId = com.CommissionId, // CustomerId = cst.CustomerId, // CustomerName = cst.CustomerName, // ERPCustomerNo = cst.ERPCustomerNo, // UserId = cst.UserId // }).ToList(); //HuiFuList = (from h in db.HuiFu // join i in db.Users on h.UserId equals i.Id // where h.UserId == userId // orderby h.Id // select new HuiFuModel() // { // CommentId = h.CommentId, // HuiFuUserId = h.HuiFuUserId, // Id = h.Id, // LouCeng = h.LouCeng, // Text = h.Text, // Time = h.Time, // UserId = h.UserId, // UserImg = i.UserImg, // UserName = i.UserName, // HuiFuUserName = b.UserName // }).ToList() }; var list = sql.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(); if (userId != 0) { //获取支持反对表 var sql1 = db.ZhiChiFanDui.Where(z => z.UserId == userId).ToList(); if (sql1.Count > 0) { //循环判断是否有支持或者反对过这条评论 //for (int i = 0; i < sql1.Count; i++) //{ // if (list[i].Id == sql1[i].CommentId && list[i].UserId == sql1[i].UserId) // { // list[i].IsZhiChiOrFanDui = true; // list[i].ZhiChiOrFanDui = sql1[i].ZhiOrFanDui; // } //} foreach (var item in list) { foreach (var item1 in sql1) { if (item.Id == item1.CommentId && item.UserId == item1.UserId) { item.IsZhiChiOrFanDui = true; item.ZhiChiOrFanDui = item1.ZhiOrFanDui; } } } } } model.cList = list; int count = sql.Count(); model.Count = count; model.pageCount = Convert.ToInt32(Math.Ceiling((double)count / (double)pageSize)); return(model); } } catch (Exception) { throw; } }