예제 #1
0
        public void Append()
        {
            using (MyDB mydb = new MyDB())
            {
                #region "创建通讯录记录"
                AddressBook AddressBook = new AddressBook
                {
                    ID = Guid.NewGuid().ToString(),
                    Name = "陈宏伟",
                    Sex = "男",
                    BirthDay = new DateTime(1971, 9, 10),
                    Company = "manbuit",
                    Department = "R&D",
                    Job = "developer",
                    Creator = mydb.Users.First(s => s.Code.Equals("lilin")),
                    Owner = mydb.Users.First(s => s.Code.Equals("lilin")),
                    AddressBookShares = new AddressBookShare[] {
                        new AddressBookShare
                        {
                            ID = Guid.NewGuid().ToString(),
                            Subject = mydb.Subjects.OfType<User>().First(s=>s.Code.Equals("lilin"))
                        },
                        new AddressBookShare
                        {
                            ID = Guid.NewGuid().ToString(),
                            Subject = mydb.Subjects.OfType<User>().First(s=>s.Code.Equals("chw"))
                        }
                    }
                };
                #endregion

                mydb.AddressBooks.Add(AddressBook);
                mydb.SaveChanges();
            }
        }
예제 #2
0
        /// <summary>
        /// 创建联系人
        /// </summary>
        /// <returns></returns>
        public ActionResult createAddress()
        {
            string Name = Request.Params["Name"];

            string userID = this.User.Identity.Name;
            using (MyDB mydb = new MyDB())
            {
                AddressBook ab = new AddressBook
                {
                    ID = Guid.NewGuid().ToString(),
                    Name = Name,
                    Creator = mydb.Users.Find(this.User.Identity.Name),
                    Owner = mydb.Users.Find(this.User.Identity.Name),
                    CreateTime = DateTime.Now,
                    LastUpdateTime = DateTime.Now
                };
                mydb.AddressBooks.Add(ab);
                mydb.SaveChanges();
                return Json(new { success = true });
            }
        }