/// <summary> /// 返回EasyChatTimeModel /// </summary> /// <param name="identity">身份</param> /// <param name="nameCn">中文名</param> /// <param name="email">邮箱</param> /// <param name="mobile">电话</param> /// <param name="personId">id</param> /// <returns></returns> public EasyChatTimeModel ReturnEasyChatTimeModel(PersonIdentity identity, string nameCn, string email, string mobile, Guid personId) { EasyChatTimeModel returnModel = new EasyChatTimeModel(); ContactIdentity contact = new ContactIdentity { PersonIdentity = identity.ToString(), NameCn = nameCn, Email = email, Mobile = mobile }; IEnumerable <EasyChatTimeEntity> easyChatTimes = null; if (identity == PersonIdentity.学生) { easyChatTimes = repository.EasyChatTime.Where(e => e.IfStudentID == personId).Select(e => e); } else { easyChatTimes = repository.EasyChatTime.Where(e => e.IfParentID == personId).Select(e => e); } returnModel.ContactIdentity = contact; returnModel.EasyChatTimes = easyChatTimes; return(returnModel); }
//根据学生ID返回Contacts List public JsonResult GetContacts(string studentID) { List <EasyChatTimeModel> contacts = new List <EasyChatTimeModel>(); //以数组形式存储所有联系人的联系时间 IEnumerable <EasyChatTimeEntity>[] chatTimes = null; //每个联系人的联系信息 ContactIdentity contactInfo = null; //所有联系人列表,从数据库中读取赋值 IEnumerable <StudentParentEntity> parents = null; if (studentID != null && studentID != string.Empty && studentID != Guid.Empty.ToString()) { Guid id = new Guid(studentID); parents = repository.StudentParent.Where(s => s.StudentID == id); } if (parents.Count() > 0) { //初始化所有联系人联系时间的数组长度 chatTimes = new IEnumerable <EasyChatTimeEntity> [parents.Count()]; for (int i = 0; i < parents.Count(); i++) { StudentParentEntity parent = parents.ElementAt(i); contactInfo = new ContactIdentity { PersonIdentity = parent.PersonIdentity.ToString(), NameCn = parent.NameCn, Mobile = parent.Mobile, Email = parent.Email, QQ = parent.QQ, Weixin = parent.Weixin }; chatTimes[i] = repository.EasyChatTime.Where(e => e.IfParentID == parent.ParentID).Select(e => e); contacts.Add(new EasyChatTimeModel { ContactIdentity = contactInfo, EasyChatTimes = chatTimes[i] }); } //以下的写法会导致chatTimes始终变成最后赋值的那个 //foreach (StudentParentEntity parent in parents) //{ // contactInfo = new ContactIdentity // { // PersonIdentity = parent.PersonIdentity.ToString(), // NameCn = parent.NameCn, // Mobile = parent.Mobile, // Email = parent.Email // }; // chatTimes = repository.EasyChatTime.Where(e => e.IfParentID == parent.ParentID).Select(e => e); // contacts.Add(new EasyChatTimeModel { ContactIdentity = contactInfo, EasyChatTimes = chatTimes }); //} } return(Json(contacts, JsonRequestBehavior.AllowGet)); }
//根据学生ID返回ContactIdentity List public JsonResult GetContactIdentityList(string studentID) { List <ContactIdentity> contacts = new List <ContactIdentity>(); //每个联系人的联系信息 ContactIdentity contactInfo = null; StudentInfoEntity studentInfo = null; //所有联系人列表,从数据库中读取赋值 IEnumerable <StudentParentEntity> parents = null; if (studentID != null && studentID != string.Empty && studentID != Guid.Empty.ToString()) { Guid id = new Guid(studentID); parents = repository.StudentParent.Where(s => s.StudentID == id); studentInfo = repository.StudentsInfo.SingleOrDefault(s => s.StudentID == id); contactInfo = new ContactIdentity { PersonIdentity = "学生", NameCn = studentInfo.NameCn, Mobile = studentInfo.Mobile, Email = studentInfo.Email }; contacts.Add(contactInfo); contactInfo = null; } if (parents.Count() > 0) { for (int i = 0; i < parents.Count(); i++) { StudentParentEntity parent = parents.ElementAt(i); contactInfo = new ContactIdentity { PersonIdentity = parent.PersonIdentity.ToString(), NameCn = parent.NameCn, Mobile = parent.Mobile, Email = parent.Email }; contacts.Add(contactInfo); contactInfo = null; } } return(Json(contacts, JsonRequestBehavior.AllowGet)); }
protected void Page_Load(object sender, EventArgs e) { // Do not check login if it's a CallBack - search button was pressed (see CreateSearchActionClientScript method) if (!RequestHelper.IsCallback()) { bool validCredential = false; try { validCredential = CheckCredential(); } catch (Exception ex) { HandleException(ex); return; } if (!validCredential) { URLHelper.Redirect(UrlResolver.ResolveUrl(LoginPageUrl)); } } try { if (!String.IsNullOrEmpty(ContactHiddenField.Value)) { JsonSerializer serializer = new JsonSerializer(); Contact freshContact = serializer.Unserialize <Contact>(ContactHiddenField.Value); if (Contact == null) { ContactForm.MergeHint = true; } else { if (Contact.ContactId != freshContact.ContactId) { ContactForm.MergeHint = true; } else if (String.IsNullOrEmpty(Contact.Phone) && String.IsNullOrEmpty(Contact.Email) && (!String.IsNullOrEmpty(freshContact.Phone) || !String.IsNullOrEmpty(freshContact.Email))) { ContactForm.MergeHint = true; ContactForm.MergeHintAttributes = new string[] { "Phone", "Email" }; } } Contact = freshContact; } ContactInfo contactInfo = EditedObject as ContactInfo; ContactIdentity identity = DataComHelper.CreateContactIdentity(contactInfo); Filter = identity.CreateFilter(); // Do not search for contact if it's a CallBack - search button was pressed (see CreateSearchActionClientScript method) if (Contact == null && !RequestHelper.IsCallback()) { DataComClient client = DataComHelper.CreateClient(); IContactProvider provider = DataComHelper.CreateContactProvider(client, credentialProvider.GetCredential()); ContactFinder finder = DataComHelper.CreateContactFinder(provider); Contact match = finder.Find(identity); if (match != null) { ShowInformation(GetString("datacom.contactmatch")); Contact = match; ContactForm.MergeHint = true; } else { ShowInformation(GetString("datacom.nocontactmatch")); } } InitializeHeaderActions(); InitializeDataComForm(); } catch (Exception exception) { HandleException(exception); } }
protected void Page_Load(object sender, EventArgs e) { ContactInfo contact = EditedObject as ContactInfo; AuthorizeReadRequest(contact); IDataComConfiguration configuration = DataComHelper.GetConfiguration(ContactSiteID); if (configuration.GetToken() == null) { ShowWarning(GetString("datacom.notoken"), null, null); } else { try { if (!String.IsNullOrEmpty(ContactHiddenField.Value)) { JsonSerializer serializer = new JsonSerializer(); Contact freshContact = serializer.Unserialize <Contact>(ContactHiddenField.Value); if (Contact == null) { ContactForm.MergeHint = true; } else { if (Contact.ContactId != freshContact.ContactId) { ContactForm.MergeHint = true; } else if (String.IsNullOrEmpty(Contact.Phone) && String.IsNullOrEmpty(Contact.Email) && (!String.IsNullOrEmpty(freshContact.Phone) || !String.IsNullOrEmpty(freshContact.Email))) { ContactForm.MergeHint = true; ContactForm.MergeHintAttributes = new string[] { "Phone", "Email" }; } } Contact = freshContact; } if (Contact == null) { ContactInfo contactInfo = EditedObject as ContactInfo; ContactIdentity identity = DataComHelper.CreateContactIdentity(contactInfo); DataComClient client = DataComHelper.CreateClient(configuration); IContactProvider provider = DataComHelper.CreateContactProvider(client, configuration); ContactFinder finder = DataComHelper.CreateContactFinder(provider); ContactFilter filterHint = null; Contact match = finder.Find(identity, out filterHint); if (match != null) { ShowInformation(GetString("datacom.contactmatch")); Contact = match; ContactForm.MergeHint = true; } else { ShowInformation(GetString("datacom.nocontactmatch")); } Filter = filterHint; } InitializeHeaderActions(); InitializeDataComForm(); } catch (Exception exception) { HandleException(exception); } } }