public string Index() { string userCode = Request.Form["user"]; string password = Request.Form["pwd"]; string title = Request.Form["title"]; string content = Request.Form["content"]; string to = Request.Form["to"]; Response.Clear(); Response.ContentType = "text/xml"; string infoID = Guid.NewGuid().ToString(); using (MyDB mydb = new MyDB()) { EntityObjectLib.User user = mydb.Users.First(u => u.Code.ToLower() == userCode.ToLower() && u.Password == password); if (user != null) { EntityObjectLib.Info info = new Info { ID = infoID, Title = title, Content = content, CreateDate = DateTime.Now, SendDate = DateTime.Now, Creator = user, SendTypes = "", Receivers = new EntityObjectLib.InfoInbox[] { new EntityObjectLib.InfoInbox { ID = Guid.NewGuid().ToString(), Receiver = mydb.Users.Find(to), ReceiveTypes = "" } } }; mydb.Infos.Add(info); mydb.SaveChanges(); return(CJX.Object2XML(new { result = true }).OuterXml); } else { return("<?xml version=\"1.0\"?><root><error>用户名口令错误!</error></root>"); } } }
// // GET: http://localhost:12480/msgService/getMyMessages?user=chw&pwd=123456&type=&start=1&length=10 /// <summary> /// 取我的指定类别的全部消息 /// 其中type,start,length可选,缺省:type为全部类型,start为零,length为100 /// type:"UR"," /// </summary> /// <returns></returns> public string Index() { List <Expression <Func <EntityObjectLib.Info, bool> > > expressions = new List <Expression <Func <EntityObjectLib.Info, bool> > >(); string userCode = Request.QueryString["user"]; string password = Request.QueryString["pwd"]; string type = Request.QueryString["type"]; if (!string.IsNullOrEmpty(type)) { expressions.Add(info => info.Type == type); } int start = Request.QueryString["start"] == null || string.IsNullOrEmpty(Request.QueryString["start"]) ? 1 : int.Parse(Request.QueryString["start"]); int length = Request.QueryString["length"] == null || string.IsNullOrEmpty(Request.QueryString["length"]) ? 100 : int.Parse(Request.QueryString["length"]); Response.Clear(); Response.ContentType = "text/xml"; using (MyDB mydb = new MyDB()) { EntityObjectLib.User user = mydb.Users.First(u => u.Code.ToLower() == userCode.ToLower() && u.Password == password); if (user != null) { IQueryable <Info> infos = mydb.InfoInboxs .Where(ib => ib.Receiver.ID == user.ID) .Select(ib => ib.Info) .OrderByDescending(info => info.CreateDate); foreach (Expression <Func <EntityObjectLib.Info, bool> > expression in expressions) { infos = infos.Where(expression); } return(CJX.Object2XML( infos.Skip(start - 1).Take(length).Select(info => new { info.ID, info.Title, Creator = info.Creator.Name, info.CreateDate, Files = mydb.InfoFiles.Count(f => f.Info.ID == info.ID) }) .ToList() .Select(info => new { info.ID, info.Title, info.Creator, CreateDate = info.CreateDate.ToString("yyyy-M-d H:m:s"), info.Files }) .ToArray() ).OuterXml); } else { return("<?xml version=\"1.0\"?><root><error>用户名口令错误!</error></root>"); } } }
/// <summary> /// 验证用户名和口令,例如:http://localhost:12480/msgService/login?user=chw&pwd=123456 /// </summary> /// <returns></returns> public string Index() { string userCode = Request.QueryString["user"]; string password = Request.QueryString["pwd"]; Response.Clear(); Response.ContentType = "text/xml"; bool result = false; using (MyDB mydb = new MyDB()) { result = mydb.Users.Count(u => u.Code.ToLower() == userCode.ToLower() && u.Password == password) > 0; return(CJX.Object2XML(new { result = result }).OuterXml); } }
// // GET: http://localhost:12480/msgService/getOrgizations?user=chw&pwd=123456 public string Index() { string userCode = Request.QueryString["user"]; string password = Request.QueryString["pwd"]; Response.Clear(); Response.ContentType = "text/xml"; using (MyDB mydb = new MyDB()) { EntityObjectLib.User user = mydb.Users.First(u => u.Code.ToLower() == userCode.ToLower() && u.Password == password); if (user != null) { mydb.Organizations.Load(); object[] result = mydb.Organizations.Local.Where(o => o.Parent == null).Select(o => getOrg(o.ID, mydb)).ToArray(); return(CJX.Object2XML(result).OuterXml); } else { return("<?xml version=\"1.0\"?><root><error>用户名口令错误!</error></root>"); } } }
// // GET: http://localhost:12480/msgService/getUsers?user=chw&pwd=123456 public string Index() { string userCode = Request.QueryString["user"]; string password = Request.QueryString["pwd"]; Response.Clear(); Response.ContentType = "text/xml"; using (MyDB mydb = new MyDB()) { bool check = mydb.Users.Count(u => u.Code.ToLower() == userCode.ToLower() && u.Password == password) > 0; if (check) { //xmlString = "<?xml version=\"1.0\"?><Root>" + // string.Join("\r\n", // mydb.Users // .OrderBy(u => u.OrderNO) // .Select(u => "<User><ID>" + u.ID + "</ID><Code>" + u.Code + "</Code><Name>" + u.Name + "</Name></User>").ToArray() // ) // + "</Root>"; //BuizApp.App_Code.CJX.Json2XML("asdf"); return(CJX.Object2XML( mydb.Users .OrderBy(u => u.OrderNO) .Select(u => new { u.ID, u.Code, u.Name }) .ToArray() ).OuterXml); } else { return("<?xml version=\"1.0\"?><root><error>用户名口令错误!</error></root>"); } } //string xmlString = string.Format("<Root><userCode>{0}</userCode><password>{1}</password></Root>", userCode, password); }