/// <summary> /// 注册 /// </summary> /// <param name="u"></param> /// <returns></returns> public int Regiest(CMS_User u) { try { db.CMS_User.Add(u); return(db.SaveChanges()); } catch (Exception) { throw; } }
/// <summary> /// 添加用户 /// </summary> /// <param name="u"></param> /// <returns></returns> public int AddUser(CMS_User u) { if (db.CMS_User.Any(c => c.uname == u.uname)) { return(-1); } else { db.CMS_User.Add(u); return(db.SaveChanges()); } }
public int UpdInfo(CMS_User u) { //db.Entry<CMS_User>(u).State = System.Data.Entity.EntityState.Modified; CMS_User ls = db.CMS_User.Find(u.uid); ls.uname = u.uname; ls.nname = u.nname; ls.face = u.face; ls.mobile = u.mobile; return(db.SaveChanges()); }
//查找用户 public ActionResult Find(int uid) { try { CMS_User userFilter = new CMS_User(); userFilter.uid = uid; var list = CMS_User_BLL.Login(userFilter); return(Json(list, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { throw ex; } }
/** * Get the author from the XML to map the post to the user. * * This allows for the "multiple authors" feature. * * @return CMS_User */ protected static CMS_User GetAuthor(kenticofreeEntities context, CONTENT_BlogPost post) { var authorname = (from p in wpxml.Descendants("item") where Int32.Parse(p.Element(wpns + "post_id").Value) == post.BlogPostID select p ).SingleOrDefault().Element(dc + "creator").Value; CMS_User kenticoUser = (from p in context.CMS_User where p.UserName == authorname select p ).SingleOrDefault(); return(kenticoUser); }
/// <summary> /// 查找用户 /// </summary> /// <param name="userFilter">用户对象</param> /// <returns>list</returns> public static dynamic Find(CMS_User userFilter) { using (CMSDatabase_Model cms = new CMSDatabase_Model()) { try { return(CMS_User_DAL.Find(userFilter)); } catch (Exception ex) { throw ex; } } }
public ActionResult FindUser(int id) { try { CMS_User userFilter = new CMS_User(); userFilter.uid = id; var list = CMS_User_BLL.Login(userFilter); return(Json(list)); } catch (Exception error) { throw error; } }
public ActionResult FindinPwd(string oldpwd, int uid) { try { CMS_User userFilter = new CMS_User(); userFilter.upwd = oldpwd; userFilter.uid = uid; var list = CMS_User_BLL.Find(userFilter); return(Json(list, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { throw ex; } }
/// <summary> /// 注册方法 /// </summary> /// <param name="user">用户</param> /// <returns>int</returns> public static dynamic Register(CMS_User user) { using (CMSDatabase_Model cms = new CMSDatabase_Model()) { try { cms.CMS_User.Add(user); var count = cms.SaveChanges(); return(count); } catch (Exception error) { throw error; } } }
/// <summary> /// 修改用户资料 /// </summary> /// <param name="user">对象</param> /// <returns>int</returns> public static dynamic Edit(CMS_User userFilter) { try { using (CMSDatabase_Model cms = new CMSDatabase_Model()) { cms.Entry(userFilter).State = System.Data.Entity.EntityState.Modified; var count = cms.SaveChanges(); return(count); } } catch (Exception ex) { throw ex; } }
/// <summary> /// 查询是否存在该用户名 /// </summary> /// <param name="userFilter">实体类对象</param> /// <returns>int;0为不存在,1为存在</returns> public static int FindUname(CMS_User userFilter) { using (CMSDatabase_Model cms = new CMSDatabase_Model()) { var list = from data in cms.CMS_User select data; foreach (var item in list.ToList()) { if (item.uname == userFilter.uname) { return(1); } } return(0); } }
public ActionResult Find(int rows, int page, string Uname) { try { CMS_User userFilter = new CMS_User(); if (!string.IsNullOrEmpty(Uname)) { userFilter.uname = Uname; } Pagination pagination = CMS_User_BLL.Find(userFilter, rows, page); return(Json(pagination, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { throw ex; } }
public ActionResult ResponseRegister(string uname, string pwd, string mobile) { try { CMS_User user = new CMS_User(); user.uname = uname; user.upwd = pwd; user.mobile = mobile; user.admin = 0; var count = CMS_User_BLL.Register(user); return(Json(count)); } catch (Exception error) { throw error; } }
public int register(CMS_User user) { user.nname = user.uname; user.admin = false; if (db.AddUser(user) > 0) { return(1); } else if (db.AddUser(user) == 0) { return(0); } else { return(-1); } }
//上传头像 public ActionResult Upload() { try { HttpFileCollectionBase files = Request.Files; HttpPostedFileBase file = files[0]; //获取文件名后缀 string extName = VirtualPathUtility.GetExtension(file.FileName).ToLower(); //获取保存目录的物理路径 if (System.IO.Directory.Exists(Server.MapPath("/images/face/")) == false)//如果不存在就创建images文件夹 { System.IO.Directory.CreateDirectory(Server.MapPath("/images/face/")); } string path = Server.MapPath("/images/face/"); //path为某个文件夹的绝对路径,不要直接保存到数据库 // string path = "F:\\TgeoSmart\\Image\\"; //生成新文件的名称,guid保证某一时刻内图片名唯一(文件不会被覆盖) string fileNewName = Guid.NewGuid().ToString(); string ImageUrl = path + fileNewName + extName; //SaveAs将文件保存到指定文件夹中 file.SaveAs(ImageUrl); //此路径为相对路径,只有把相对路径保存到数据库中图片才能正确显示(不加~为相对路径) string url = "\\/images/face/\\" + fileNewName + extName; if (!string.IsNullOrEmpty(url)) //修改数据库 { CMS_User userFilter = new CMS_User(); userFilter.uid = Convert.ToInt32(Session["userID"]); var list = CMS_User_BLL.Find(userFilter); list[0].face = fileNewName + extName; CMS_User_BLL.Edit(list[0]); } return(Json(new { Result = true, Data = url })); } catch (Exception exception) { return(Json(new { Result = false, exception.Message })); } }
//注册 public int AddUser(CMS_User user) { var ls = db.CMS_User.Any(c => c.uname == user.uname); if (ls) { return(0); } db.CMS_User.Add(user); if (db.SaveChanges() > 0) { return(1); } else { return(-1); } }
public ActionResult ResponseLogin(string uname, string pwd) { try { CMS_User userFilter = new CMS_User(); userFilter.uname = uname; userFilter.upwd = pwd; var list = CMS_User_BLL.Login(userFilter); if (list.Count > 0) { CMS_User user = list[0] as Model.CMS_User; Session["userID"] = user.uid; } return(Json(list)); } catch (Exception error) { throw error; } }
/// <summary> /// 查询一个用户的回复次数 /// </summary> /// <param name="userFilter">对象</param> /// <returns>int</returns> public static dynamic FindComSum(CMS_User userFilter) { try { using (CMSDatabase_Model cms = new CMSDatabase_Model()) { var list = from data in cms.CMS_Comment select data; if (userFilter.uid > 0) { list = list.Where(data => data.uid == userFilter.uid).Select(data => data); } var count = list.Count(); return(count); } } catch (Exception ex) { throw ex; } }
// GET: Personal_Profile public ActionResult Personal_Profile(int uid = 0) { try { if (uid == 0) { Response.Redirect("/Login/Login"); } CMS_User userFilter = new CMS_User(); userFilter.uid = uid; List <CMS_User> list = CMS_User_BLL.Login(userFilter); //查询用户 ViewBag.userList = list; var countInCommentSum = CMS_User_BLL.FindComSum(userFilter); //查询用户评论数 ViewBag.countInCommentSum = countInCommentSum; return(View()); } catch (Exception error) { throw error; } }
public ActionResult AdminLogin(string uname, string upwd) { upwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(upwd, "MD5"); CMS_User ls = d1.CMS_User.FirstOrDefault(c => c.uname == uname && c.upwd == upwd); if (ls.admin == true) { Session["admin"] = ls; return(Json(new { msg = "管理员" + ls.uname + "登录成功", state = true })); } else { return(Json(new { msg = "管理员或密码错误", state = false })); } }
public ActionResult UpdInfo(CMS_User u) { u.uid = (Session["user"] as CMS_User).uid; if (db.UpdInfo(u) > 0) { Session.Clear(); Session["user"] = u; return(Json(new { state = 1, message = "修改成功" })); } else { return(Json(new { state = 0, message = "修改失败" })); } }
/// <summary> /// 查找用户 /// </summary> /// <param name="userFilter">用户对象</param> /// <returns>list</returns> public static dynamic Find(CMS_User userFilter) { using (CMSDatabase_Model cms = new CMSDatabase_Model()) { try { var list = from data in cms.CMS_User select data; if (userFilter.uid > 0) { list = list.Where(data => data.uid == userFilter.uid).Select(data => data); } if (!string.IsNullOrEmpty(userFilter.upwd)) { list = list.Where(data => data.upwd == (userFilter.upwd)).Select(data => data); } return(list.ToList()); } catch (Exception ex) { throw ex; } } }
public ActionResult Edit(int uid) { try { CMS_User userFilter = new CMS_User(); userFilter.uid = uid; Pagination pagination = CMS_User_BLL.Find(userFilter, 10, 1); List <CMS_User> list = pagination.rows as List <CMS_User>; if (list[0].admin == 0) { list[0].admin = 1; } else if (list[0].admin == 1) { list[0].admin = 0; } var count = CMS_User_BLL.Edit(list[0]); return(Json(count, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { throw ex; } }
public int AddUser(CMS_User u) { u.face = "images/face.jpg"; u.upwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(u.upwd, "MD5"); return(db.AddUser(u)); }
/// <summary> /// 用户信息 /// </summary> /// <returns></returns> public ActionResult Info() { CMS_User u = Session["user"] as CMS_User; return(View(u)); }
/// <summary> /// 查询是否存在该用户名 /// </summary> /// <param name="userFilter">实体类对象</param> /// <returns>int;0为不存在,1为存在</returns> public static int FindUname(CMS_User userFilter) { return(CMS_User_DAL.FindUname(userFilter)); }
public int editUser(CMS_User u) { db.Entry <CMS_User>(u).State = System.Data.Entity.EntityState.Modified; return(db.SaveChanges()); }
public int Adduser(CMS_User u) { db.CMS_User.Add(u); return(db.SaveChanges()); }
/** * Import Post * * Imports a given post into the database, creating the necessary dependencies, * including BlogMonth (if it doesn't already exist), TreeNode, and Document. * Returns the newly-created document that represents the post. * * @param entities context * @param CMS_Tree blog * @param CONTENT_BlogPost post * @return CMS_Document */ protected static CMS_Document ImportPost(kenticofreeEntities context, CMS_Tree blog, CONTENT_BlogPost post) { Regex forbidden = new Regex(forbiddenChars); Regex consolidateDashes = new Regex("[-]{2}"); /* We want to preserve the IDs of the Posts for linking, but EF won't let us turn on IDENTITY_INSERT * with its available methods (ExecuteStoreCommand and SaveChanges are different connections, it seems). * So we have to do it the old fashioned way. */ object[] values = new object[] { post.BlogPostID.ToString(), post.BlogPostTitle, post.BlogPostDate.Date.ToString("yyyy-MM-dd HH:mm:ss"), post.BlogPostSummary, post.BlogPostAllowComments, post.BlogPostBody, post.BlogLogActivity }; /* We'll use MERGE here, so that we can handle existing entries. * The "xmlTrumpsDb" config switch will allow a choice between nuking what's in the DB * or preserving it. */ string cmd = "SET IDENTITY_INSERT CONTENT_BlogPost ON; "; cmd += "MERGE CONTENT_BlogPost "; cmd += "USING (VALUES ({0},{1},{2},{3},{4},{5},{6})) as temp(BlogPostID, BlogPostTitle, BlogPostDate, BlogPostSummary, BlogPostAllowComments, BlogPostBody, BlogLogActivity) "; cmd += "ON CONTENT_BlogPost.BlogPostID = temp.BlogPostID "; // To nuke or not to nuke, that is the question... if (config.Get("xmlTrumpsDb") == "true") { cmd += "WHEN MATCHED THEN "; cmd += "UPDATE SET CONTENT_BlogPost.BlogPostTitle = temp.BlogPostTitle, CONTENT_BlogPost.BlogPostDate = temp.BlogPostDate, CONTENT_BlogPost.BlogPostSummary = temp.BlogPostSummary, CONTENT_BlogPost.BlogPostAllowComments = temp.BlogPostAllowComments, CONTENT_BlogPost.BlogPostBody = temp.BlogPostBody, CONTENT_BlogPost.BlogLogActivity = temp.BlogLogActivity "; } cmd += "WHEN NOT MATCHED THEN "; cmd += "INSERT (BlogPostId, BlogPostTitle, BlogPostDate, BlogPostSummary, BlogPostAllowComments, BlogPostBody, BlogLogActivity) VALUES ({0},{1},{2},{3},{4},{5},{6}); "; cmd += "SET IDENTITY_INSERT CONTENT_BlogPost OFF;"; context.ExecuteStoreCommand(cmd, values); // See if there's a BlogMonth entry for the month this post is for CMS_Tree month = GetBlogMonth(context, post, blog); CMS_Class blogClass = context.CMS_Class.Where(x => x.ClassName == "CMS.BlogPost").First(); CMS_Tree treeNode = (from t in context.CMS_Tree join d in context.CMS_Document on t.NodeID equals d.DocumentNodeID where d.DocumentForeignKeyValue == post.BlogPostID && t.NodeClassID == 3423 select t).FirstOrDefault(); // Add a new node only if one doesn't already exist if (treeNode == null) { string nodeAlias = consolidateDashes.Replace(forbidden.Replace(post.BlogPostTitle, "-"), "-"); nodeAlias = (nodeAlias.Length > 50 ? nodeAlias.Substring(0, 50) : nodeAlias); // Truncate the alias to avoid SQL Server errors // Create the Tree Node for the post and add it in treeNode = new CMS_Tree() { NodeAliasPath = string.Format("{0}/{1}", month.NodeAliasPath, forbidden.Replace(post.BlogPostTitle, "-")), NodeName = post.BlogPostTitle, NodeAlias = nodeAlias, NodeClassID = blogClass.ClassID, NodeParentID = month.NodeID, NodeLevel = Int32.Parse(config.Get("kenticoBlogLevel")) + 2, NodeACLID = 1, // Default ACL ID NodeSiteID = siteId, NodeGUID = Guid.NewGuid(), NodeInheritPageLevels = "", NodeTemplateForAllCultures = true, NodeChildNodesCount = 0 }; CMS_User author = GetAuthor(context, post); treeNode.NodeOwner = author.UserID; context.CMS_Tree.AddObject(treeNode); treeNode.NodeOrder = GetNodeOrder(context, treeNode); month.NodeChildNodesCount++; // Increment the child nodes count, so the new post will display in the CMS blog.NodeChildNodesCount++; // Increment the blog's child nodes count, too. context.SaveChanges(); } CMS_TagGroup tagGroup = GetTagGroup(context); // Create the document and add it into the database CMS_Document postDoc = AddDocument(context, treeNode, post.BlogPostID, tagGroup.TagGroupID); return(postDoc); }
public CMS_User getUserByid(int uid) { CMS_User u = db.CMS_User.Find(uid); return(u); }