void myContactInfoDetail_OnPrimaryClick(object sender, EventArgs e) { int catlogId = Convert.ToInt32(Request.QueryString["CatlogID"]); int userId =(int) Session[SessionConstance.USER_ID]; // 查看该catlogId是否属于该userId var catlog = from x in db.Catlogs where x.Owner == userId && x.CatlogID == catlogId select x; if (catlog.Count() == 0) { Jinhaoxia.Util.AlterMessage.ShowMessage(this.Page, "当前通讯录不存在"); return; } // 该通讯录存在,且属于当前用户,创建ContactInfo实体,并加入数据库 XContactModel.ContactInfo contactInfo = new XContactModel.ContactInfo(); contactInfo.Name = myContactInfoDetail.Name; contactInfo.Description = myContactInfoDetail.Description; contactInfo.Gender = myContactInfoDetail.Gender; contactInfo.Email = myContactInfoDetail.Email; contactInfo.TelephoneNumber = myContactInfoDetail.TelephoneNumber; contactInfo.MobilePhoneNumber = myContactInfoDetail.MobilePhoneNumber; contactInfo.OfficePhoneNumber = myContactInfoDetail.OfficePhoneNumber; contactInfo.HomePhoneNumber = myContactInfoDetail.HomePhoneNumber; contactInfo.BelongsTo = catlogId; db.AddToContactInfoes(contactInfo); if (db.SaveChanges() > 0) { Jinhaoxia.Util.AlterMessage.ShowMessageAndGoHistory(this.Page, "创建成功!", -2); } else { Jinhaoxia.Util.AlterMessage.ShowMessage(this.Page, "创建失败"); } }
/// <summary> /// 创建新的 ContactInfo 对象。 /// </summary> /// <param name="contactInfoID">ContactInfoID 属性的初始值。</param> /// <param name="name">Name 属性的初始值。</param> /// <param name="belongsTo">BelongsTo 属性的初始值。</param> public static ContactInfo CreateContactInfo(global::System.Int32 contactInfoID, global::System.String name, global::System.Int32 belongsTo) { ContactInfo contactInfo = new ContactInfo(); contactInfo.ContactInfoID = contactInfoID; contactInfo.Name = name; contactInfo.BelongsTo = belongsTo; return contactInfo; }
/// <summary> /// 用于向 ContactInfoes EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet<T> 属性的 .Add 方法。 /// </summary> public void AddToContactInfoes(ContactInfo contactInfo) { base.AddObject("ContactInfoes", contactInfo); }