private static void EnsureContactPrimary(IAccContactInfo contact, ISession session) { if (contact.ContactType.Contains("Тел")) { var queryList = session.CreateSQLQuery($"select ACC_CONTACT_INFOID from ACC_CONTACT_INFO where ACCOUNTID = '{ contact.AccountId }'").AddScalar("ACC_CONTACT_INFOID", NHibernateUtil.String).List <String>(); if (queryList == null || queryList.Count < 1) { return; } foreach (var contactId in queryList) { var foundContact = EntityFactory.GetById <IAccContactInfo>(contactId); if (foundContact != null && foundContact.Id != null && foundContact.Id != contact.Id && foundContact.ContactType != null && foundContact.ContactType.Contains("Тел")) { foundContact.IsMain = false; } } } if (contact.ContactType.ToLower().Contains("e-mail") || contact.ContactType.ToLower().Contains("email")) { var queryList = session.CreateSQLQuery($"select ACC_CONTACT_INFOID from ACC_CONTACT_INFO where ACCOUNTID = '{ contact.AccountId }'").AddScalar("ACC_CONTACT_INFOID", NHibernateUtil.String).List <String>(); if (queryList == null || queryList.Count < 1) { return; } foreach (var contactId in queryList) { var foundContact = EntityFactory.GetById <IAccContactInfo>(contactId); if (foundContact != null && foundContact.Id != null && foundContact.Id != contact.Id && foundContact.ContactType != null && (foundContact.ContactType.ToLower().Contains("e-mail") || foundContact.ContactType.ToLower().Contains("email"))) { foundContact.IsMain = false; } } } }
public static void OnBeforeDeleteStep(IAccContactInfo contact, ISession session) { if (contact == null) { return; } // обновить контакты CommonProcedures.UpdateAccountContacts(contact.AccountId, session); }
public static void OnBeforeInsertStep(IAccContactInfo contact, ISession session) { if (contact == null && contact.IsMain == false && contact.Account == null && contact.ContactType == null) { return; } EnsureContactPrimary(contact, session); // обновить контакты CommonProcedures.UpdateAccountContacts(contact.AccountId, session); }
public static void CheckAccContactInfoStep(IAccNewsletter accnewsletter) { if (!String.IsNullOrEmpty(accnewsletter.Email)) { IQueryable qry = EntityFactory.GetRepository <IAccContactInfo>() as IQueryable; IExpressionFactory ep = qry.GetExpressionFactory(); ICriteria crt = qry.CreateCriteria(); crt.Add(ep.Eq("AccountId", accnewsletter.Accountid)); crt.Add(ep.Eq("ContactValue", accnewsletter.Email)); IList <IAccContactInfo> lst = crt.List <IAccContactInfo>(); if (lst.Count > 0) { foreach (IAccContactInfo vEntity in lst) { vEntity.Comments = "Рассылка сведений об операциях"; vEntity.IsActual = true; vEntity.Save(); } } else { IAccContactInfo com = EntityFactory.Create <IAccContactInfo>(); com.AccountId = accnewsletter.Accountid; com.IsActual = true; if (accnewsletter.DeliveryType.Contains("E-mail")) { com.ContactType = "E-mail для рассылки"; } else { com.ContactType = "Телефон для рассылки"; } com.Comments = "Рассылка сведений об операциях"; com.ContactValue = accnewsletter.Email; com.Save(); } } }