public string donews() { string title = Request["title"]; string author = Request["author"]; DateTime addtime = DateTime.Parse(Request["addtime"]); string content = Request["content"]; var db = new airenEntities(); //id 为空 添加 if (string.IsNullOrWhiteSpace(Request["id"])) { news news = new news(); news.Title = title; news.Author = author; news.AddTime = addtime; news.Content = content; db.news.Add(news); db.SaveChanges(); return("success"); } //id 不为空 修改 else { int id = int.Parse(Request["id"]); var nws = db.news.Where(n => n.ID == id).FirstOrDefault(); nws.Title = title; nws.Author = author; nws.AddTime = addtime; nws.Content = content; db.SaveChanges(); return("success1"); } }
public string dopwd() { string phone = Request["phone"]; string pwd = Request["pwd"]; if (!string.IsNullOrWhiteSpace(pwd)) { airenEntities db = new airenEntities(); //var info = from p in db.user // where p.Phone == phone && p.Password == pwd // select p; var list = db.user.Where(p => p.Phone == phone).FirstOrDefault(); if (list != null) { list.Password = pwd; list.Confirmpwd = pwd; db.SaveChanges(); return("success"); } else { return("error"); } } else { return("error"); } }
public string outuser() { var db = new airenEntities(); string phone = Request["phone"]; var user = db.user.Where(p => p.Phone == phone).FirstOrDefault(); user.IsOnline = "离线"; db.SaveChanges(); return("success"); }
public string delete() { string ids = Request["ids"]; var db = new airenEntities(); foreach (var item in ids.Split(',')) { int id = Convert.ToInt32(item); var nws = db.news.Where(n => n.ID == id).FirstOrDefault(); db.news.Remove(nws); } db.SaveChanges(); return("success"); }
public string dolog() { string phone = Request["phone"]; string pwd = Request["pwd"]; string UserID; if (!string.IsNullOrWhiteSpace(phone) && !string.IsNullOrWhiteSpace(pwd)) { airenEntities db = new airenEntities(); //var info = from p in db.user // where p.Phone == phone && p.Password == pwd // select p; var list = db.user.Where(p => p.Phone == phone && p.Password == pwd).FirstOrDefault(); if (list != null) { Session["phone"] = phone; Session["pwd"] = pwd; UserID = list.ID.ToString(); Session["id"] = UserID; list.IsOnline = "在线"; HttpCookie cookie = new HttpCookie("Myuser"); cookie.Values["phone"] = phone; cookie.Values["pwd"] = pwd; cookie.Values["userid"] = UserID; //cookie.Values.Add("username", username); //cookie.Values.Add("pwd", pwd); cookie.Expires = DateTime.Now.AddSeconds(600); Response.AppendCookie(cookie); db.SaveChanges(); if (list.Type == "管理员") { return("super"); } return("success"); } else { return("error"); } } else { return("error"); } }
public string exit() { var db = new airenEntities(); string phone; if (Session["phone"] != null) { phone = Session["phone"].ToString(); } else { phone = Request.Cookies["Myuser"]["phone"].ToString(); } var user = db.user.Where(p => p.Phone == phone).FirstOrDefault(); user.IsOnline = "离线"; db.SaveChanges(); return("success"); }
public string doReg() { string phone = Request["phone"]; string pwd = Request["pwd"]; if (!string.IsNullOrWhiteSpace(phone) && !string.IsNullOrWhiteSpace(pwd)) { airenEntities db = new airenEntities(); user user = new user(); user.Phone = phone; user.Password = pwd; user.Confirmpwd = pwd; user.Type = "普通用户"; db.user.Add(user); db.SaveChanges(); return("success"); } else { return("error"); } }
public string doinfo() { string phone = Request["phone"]; string name = Request["name"]; string bday = Request["bday"]; string age = Request["age"]; string pro = Request["pro"]; string sex = Request["sex"]; if (!string.IsNullOrWhiteSpace(phone)) { airenEntities db = new airenEntities(); //var info = from p in db.user // where p.Phone == phone && p.Password == pwd // select p; var list = db.user.Where(p => p.Phone == phone).First(); if (list != null) { list.Name = name; if (!string.IsNullOrWhiteSpace(bday)) { list.Birthday = DateTime.Parse(bday); } list.Age = age; list.Profession = pro; list.Sex = sex; db.SaveChanges(); return("success"); } else { return("error"); } } else { return("error"); } }
public string doupload() { string url = ""; HttpPostedFileBase _file; airenEntities db = new airenEntities(); for (int i = 0; i < Request.Files.Count; i++) { _file = Request.Files[i]; if (_file.ContentLength > 0) { url = Server.MapPath("~/upload/") + _file.FileName; _file.SaveAs(url); file fi = new file(); fi.FileName = _file.FileName; fi.FilePath = url; fi.UserID = Request.Cookies["Myuser"]["userid"]; db.file.Add(fi); db.SaveChanges(); } } return(""); }