Ejemplo n.º 1
0
        public ActionResult MsgSend()
        {
            // 如果字符串含双引号,则将截断双引号及后面的字符,但在其他表单里是没有的,可能与
            // 该表单含文件上传有关
            string Receivers = Request.Form["Receivers"];
            string Title = Request.Form["Title"];
            string Content = Request.Form["Content"].Replace("\r\n",""); //去掉回车
            string ParentID = Server.HtmlEncode(Request.Form["ParentID"]);
            string hiddenFileIDs = Request.Form["hiddenFileIDs"];

            string infoID = Guid.NewGuid().ToString();
            using (MyDB mydb = new MyDB())
            {
                EntityObjectLib.File[] files = mydb.Files.Where(f => hiddenFileIDs.Contains(f.ID)).ToArray();
                EntityObjectLib.Info info = new Info
                {
                    ID = infoID,
                    Title = Title,
                    Content = Content,
                    CreateDate = DateTime.Now,
                    SendDate = DateTime.Now,
                    Creator = mydb.Users.Find(HttpContext.User.Identity.Name),
                    SendTypes = "",
                    Receivers = string.IsNullOrEmpty(Receivers) ? null : Receivers.Split(",".ToCharArray()).Select(r => new EntityObjectLib.InfoInbox
                    {
                        ID = Guid.NewGuid().ToString(),
                        Receiver = mydb.Users.FirstOrDefault(u => r.Equals(u.Name + "(" + u.Code + ")")),
                        ReceiveTypes = ""
                    }).ToArray(),
                    InfoFiles = files.Select(f =>
                            new InfoFile
                            {
                                ID = Guid.NewGuid().ToString(),
                                File = f,
                                FileName = f.Name,
                                UploadDate = DateTime.Now
                            }
                        ).ToArray(),
                    Parent = mydb.Infos.Find(ParentID)/*,
                    Board = mydb.InfoBoards.First()*/
                };
                /*
                List<EntityObjectLib.File> files = new List<EntityObjectLib.File>();
                for (int i = 0; i < Request.Files.Count; i++)
                {

                    if (Request.Files[i].ContentLength > 0)
                    {
                        Request.Files[i].SaveAs(Server.MapPath("~/" + Request.Files[i].FileName));

                        EntityObjectLib.File file = new EntityObjectLib.File
                        {
                            ID = Guid.NewGuid().ToString(),
                            CreateDate = DateTime.Now,
                            Name = Request.Files[i].FileName,
                            Creator = mydb.Users.Find(HttpContext.User.Identity.Name),
                            UploadPath = "~/",
                            Suffix = ""
                        };
                        files.Add(file);
                    }
                }
                */

                mydb.Infos.Add(info);

                mydb.SaveChanges();
            }

            Response.Clear();
            return Json(new { success = true, ID = infoID }, "text/html");
        }
Ejemplo n.º 2
0
        public void TestMethod1()
        {
            using (MyDB mydb = new MyDB())
            {
                Info info = new Info
                {
                    ID = Guid.NewGuid().ToString(),
                    Title = "这是一个测试",
                    Content = "Content",
                    Creator = mydb.Users.FirstOrDefault(u=>u.Code=="chw"),
                    CreateDate = DateTime.Now,
                    SendDate = DateTime.Now,
                    SendTypes = "SMS,Msg,Email",
                    InfoFiles = new InfoFile[]
                    {
                        new InfoFile
                        {
                             ID = Guid.NewGuid().ToString(),
                             FileName = "WWW.doc",
                             UploadDate = DateTime.Now,
                             File = new File
                             {
                                 ID = Guid.NewGuid().ToString(),
                                 Name = "XXX",
                                 Suffix = "doc",
                                 CreateDate = DateTime.Now,
                                 Creator = mydb.Users.FirstOrDefault(u=>u.Code=="chw"),
                                 UploadPath = "~/uploads"
                             }
                        },
                        new InfoFile
                        {
                             ID = Guid.NewGuid().ToString(),
                             FileName = "XXX.jpg",
                             UploadDate = DateTime.Now,
                             File = new File
                             {
                                 ID = Guid.NewGuid().ToString(),
                                 Name = "XXX",
                                 Suffix = "jpg",
                                 CreateDate = DateTime.Now,
                                 Creator = mydb.Users.FirstOrDefault(u=>u.Code=="chw"),
                                 UploadPath = "~/uploads"
                             }
                        }
                    },
                    Receivers = new InfoInbox[]
                    {
                        new InfoInbox
                        {
                            ID=Guid.NewGuid().ToString(),
                            Receiver = mydb.Users.FirstOrDefault(u=>u.Code=="chw"),
                            ReadDate = DateTime.Now,
                            ReceiveTypes =  "SMS,Msg,Email"
                        },
                        new InfoInbox
                        {
                            ID=Guid.NewGuid().ToString(),
                            Receiver = mydb.Users.FirstOrDefault(u=>u.Code=="lilin"),
                            ReadDate = DateTime.Now,
                            ReceiveTypes =  "SMS,Msg,Email"
                        },
                    }
                };

                InfoBoard board = new InfoBoard
                {
                    ID = Guid.NewGuid().ToString(),
                    Name = "dfadsfa",
                    Administrator = mydb.Users.FirstOrDefault(u => u.Code == "lilin"),
                    CreateDate = DateTime.Now,
                    Infos = new []{info}
                };

                InfoSubscription sub = new InfoSubscription
                {
                    ID= Guid.NewGuid().ToString(),
                    Owner = mydb.Users.FirstOrDefault(u => u.Code == "lilin"),
                    Title = info,
                    Name = "sdsss",
                    Enable = true,
                    CreateDate = DateTime.Now
                };

                mydb.Infos.Add(info);
                mydb.InfoBoards.Add(board);
                mydb.InfoSubscriptions.Add(sub);

                mydb.SaveChanges();
            }
        }
Ejemplo n.º 3
0
        private static void SendRemind(User user, string title, string Content, MyDB db)
        {
            User sender = db.Users.First(u => u.Code.Equals("remindRobot")); //后台模拟用户
            Info info = new Info()
            {
                ID = Guid.NewGuid().ToString(),
                Title = "[提醒]"+title,
                Content = Content,
                CreateDate = DateTime.Now,
                SendDate = DateTime.Now,
                Creator = sender,
                SendTypes = "",
                Type = "提醒",
                Receivers = new InfoInbox[]
                    {
                        new InfoInbox {
                        ID = Guid.NewGuid().ToString(),
                        Receiver = user,
                        ReceiveTypes = ""
                        }
                    }
            };

            db.Infos.Add(info);
        }