Example #1
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();
            }
        }
Example #2
0
        public ActionResult updateMySubscriptions()
        {
            IEnumerable<string> Ids = Request.Params["IDs"].Split(",".ToArray()).AsEnumerable(); //新的角色ID串
            string userID = this.User.Identity.Name;
            using (MyDB mydb = new MyDB())
            {
                IQueryable<InfoSubscription> subscriptions = mydb.InfoSubscriptions.Where(s => s.Owner.ID.Equals(userID));

                foreach (InfoSubscription s in subscriptions)
                {
                    if(!Ids.Contains(s.Title.ID))
                        mydb.InfoSubscriptions.Remove(s);
                }

                string[] appendIDS = Ids.Except(subscriptions.Select(s=>s.Title.ID)).ToArray();
                foreach (string s in appendIDS)
                {
                    InfoSubscription sub = new InfoSubscription();
                    sub.ID = Guid.NewGuid().ToString();
                    sub.Owner = mydb.Users.Find(userID);
                    sub.Title = mydb.Infos.Find(s);

                    mydb.InfoSubscriptions.Add(sub);
                }
                mydb.SaveChanges();
            }
            return Json(new { success = true });
        }