private void CreateSmsForContact(string prefix, string sms, int contactId) { CommunicationSmsRecord csr = new CommunicationSmsRecord(); csr.Prefix = prefix; csr.Sms = sms; csr.DataInserimento = DateTime.Now; csr.DataModifica = DateTime.Now; csr.Produzione = true; csr.Validated = true; csr.SmsContactPartRecord_Id = contactId; _repositoryCommunicationSmsRecord.Create(csr); }
public void Synchronize() { #region lego tutti gli sms var alluser = _orchardServices.ContentManager.Query <UserPart, UserPartRecord>().Where(x => x.RegistrationStatus == UserStatus.Approved); if (alluser.List().FirstOrDefault().As <UserPwdRecoveryPart>() != null) { var allusercol = alluser.List().Where(x => !string.IsNullOrEmpty(x.ContentItem.As <UserPwdRecoveryPart>().PhoneNumber)).ToList(); foreach (IContent user in allusercol) { string pref = user.ContentItem.As <UserPwdRecoveryPart>().InternationalPrefix; string num = user.ContentItem.As <UserPwdRecoveryPart>().PhoneNumber; CommunicationSmsRecord csr = _repositoryCommunicationSmsRecord.Fetch(x => x.Sms == num && x.Prefix == pref).FirstOrDefault(); CommunicationContactPart ciCommunication = _orchardServices.ContentManager.Query <CommunicationContactPart, CommunicationContactPartRecord>().Where(x => x.UserPartRecord_Id == user.Id).List().FirstOrDefault(); if (ciCommunication == null) { // Una contact part dovrebbe esserci in quanto questo codice viene eseguito dopo la sincronizzazione utenti // Se non vi è una contartpart deduco che il dato sia sporco (es: UUid di un utente che è stato cancellato quindi non sincronizzo il dato con contactpart, verrà legato come se fosse scollegato al contentitem che raggruppa tutti i scollegati) //throw new Exception("Utente senza associazione alla profilazione"); } else { if (csr == null) { CommunicationSmsRecord newsms = new CommunicationSmsRecord(); newsms.Prefix = pref; newsms.Sms = num; newsms.SmsContactPartRecord_Id = ciCommunication.ContentItem.Id; newsms.Id = 0; newsms.Validated = true; newsms.DataInserimento = DateTime.Now; newsms.DataModifica = DateTime.Now; newsms.Produzione = true; _repositoryCommunicationSmsRecord.Create(newsms); _repositoryCommunicationSmsRecord.Flush(); } else { if (csr.SmsContactPartRecord_Id != ciCommunication.ContentItem.Id) { csr.SmsContactPartRecord_Id = ciCommunication.ContentItem.Id; csr.DataModifica = DateTime.Now; _repositoryCommunicationSmsRecord.Update(csr); _repositoryCommunicationSmsRecord.Flush(); } } } } } #endregion }
/// <summary> /// Data una Hashtable frutto di una query HQL e di un AliasToEntityMap, cerca la componenete SmsContactPartRecord /// e ne estrae il numero di telefono (prefisso + numero). /// </summary> /// <param name="content"></param> /// <returns></returns> private string GetPhoneNumber(Hashtable content) { string risultato = ""; SmsContactPartRecord contactRecord = null; CommunicationSmsRecord smsRecord = null; // Send for Contact Part if (content.ContainsKey("SmsContactPartRecord")) { contactRecord = (content["SmsContactPartRecord"] as SmsContactPartRecord); if ((contactRecord.SmsRecord != null) && (contactRecord.SmsRecord.Count > 0)) { smsRecord = contactRecord.SmsRecord[0]; risultato = smsRecord.Prefix + smsRecord.Sms; } } // Send for Lista Destinatari else if (content.ContainsKey("SmsContactNumber")) { risultato = content["SmsContactNumber"].ToString(); } ////versione senza l'uso degli alias nella query HQL //foreach (DictionaryEntry obj in content) //{ // if (obj.Value.GetType() == typeof(SmsContactPartRecord)) // { // contactRecord = (obj.Value as SmsContactPartRecord); // if ((contactRecord.SmsRecord != null) && (contactRecord.SmsRecord.Count > 0)) // { // smsRecord = contactRecord.SmsRecord[0]; // risultato = smsRecord.Prefix + smsRecord.Sms; // break; // } // } //} return(risultato); }
public void AddSmsToContact(string pref, string num, ContentItem contact, bool overridexisting = true) { if (!string.IsNullOrEmpty(num)) { CommunicationContactPart ciCommunication = contact.As <CommunicationContactPart>(); if (ciCommunication != null) { CommunicationSmsRecord csr = _repositoryCommunicationSmsRecord.Fetch(x => x.SmsContactPartRecord_Id == ciCommunication.ContentItem.Id).FirstOrDefault(); if (csr == null) { CommunicationSmsRecord newsms = new CommunicationSmsRecord(); newsms.Prefix = pref; newsms.Sms = num; newsms.SmsContactPartRecord_Id = ciCommunication.ContentItem.Id; newsms.Id = 0; newsms.Validated = true; newsms.DataInserimento = DateTime.Now; newsms.DataModifica = DateTime.Now; newsms.Produzione = true; _repositoryCommunicationSmsRecord.Create(newsms); _repositoryCommunicationSmsRecord.Flush(); } else { if (overridexisting) { csr.Prefix = pref; csr.Sms = num; csr.SmsContactPartRecord_Id = ciCommunication.ContentItem.Id; csr.DataModifica = DateTime.Now; _repositoryCommunicationSmsRecord.Update(csr); _repositoryCommunicationSmsRecord.Flush(); } } } } }
protected override DriverResult Editor(SmsContactPart part, IUpdateModel updater, dynamic shapeHelper) { View_SmsVM oldviewModel = new View_SmsVM(); updater.TryUpdateModel(oldviewModel, Prefix, null, null); bool error = false; _transaction.Demand(); foreach (View_SmsVM_element vmel in oldviewModel.Elenco) { if ((vmel.Delete || string.IsNullOrEmpty(vmel.Sms)) && vmel.Id > 0) { CommunicationSmsRecord cmr = _repoSms.Fetch(x => x.Id == vmel.Id).FirstOrDefault(); _repoSms.Delete(cmr); } else if (!vmel.Delete) { if (!string.IsNullOrEmpty(vmel.Sms)) { if (_repoSms.Fetch(x => x.Sms == vmel.Sms && x.Prefix == vmel.Prefix && x.Id != vmel.Id).Count() > 0) { error = true; updater.AddModelError("Error", T("Sms can't be assigned is linked to other contact")); } } if (vmel.Id > 0) { CommunicationSmsRecord cmr = _repoSms.Fetch(x => x.Id == vmel.Id).FirstOrDefault(); if (cmr.Sms != vmel.Sms || cmr.Prefix != vmel.Prefix || cmr.Validated != vmel.Validated || cmr.AccettatoUsoCommerciale != vmel.AccettatoUsoCommerciale || cmr.AutorizzatoTerzeParti != vmel.AutorizzatoTerzeParti) { cmr.Sms = vmel.Sms; cmr.Prefix = vmel.Prefix; cmr.Validated = vmel.Validated; cmr.AccettatoUsoCommerciale = vmel.AccettatoUsoCommerciale; cmr.AutorizzatoTerzeParti = vmel.AutorizzatoTerzeParti; cmr.DataModifica = DateTime.Now; _repoSms.Update(cmr); } } else { View_SmsVM_element vm = new View_SmsVM_element(); CommunicationSmsRecord cmr = new CommunicationSmsRecord(); _mapper.Map <View_SmsVM_element, CommunicationSmsRecord>(vm, cmr); cmr.Sms = vmel.Sms; cmr.Validated = vmel.Validated; cmr.AccettatoUsoCommerciale = vmel.AccettatoUsoCommerciale; cmr.AutorizzatoTerzeParti = vmel.AutorizzatoTerzeParti; cmr.Prefix = vmel.Prefix; cmr.SmsContactPartRecord_Id = part.Id; _repoSms.Create(cmr); } } } if (error == true) { _transaction.Cancel(); } else { _repoSms.Flush(); } return(Editor(part, shapeHelper)); }
/// <summary> /// /// </summary> /// <param name="part"></param> /// <param name="context"></param> protected override void Importing(SmsContactPart part, ImportContentContext context) { var importedSmsRecord = context.Data.Element(part.PartDefinition.Name).Elements("SmsRecord"); if (importedSmsRecord != null) { if (part.SmsRecord == null) { part.SmsRecord = new List <CommunicationSmsRecord>(); } foreach (var sms in importedSmsRecord) { string locPrefix = ""; var Prefix = sms.Attribute("Prefix"); if (Prefix != null) { locPrefix = Prefix.Value; } string locSms = ""; var Sms = sms.Attribute("Sms"); if (Sms != null) { locSms = Sms.Value; } CommunicationSmsRecord comSms = part.Record.SmsRecord.FirstOrDefault(x => x.Prefix == locPrefix && x.Sms == locSms); if (comSms == null) { comSms = new CommunicationSmsRecord(); comSms.SmsContactPartRecord_Id = part.Id; comSms.Prefix = locPrefix; comSms.Sms = locSms; _repoSms.Create(comSms); part.SmsRecord.Add(comSms); } var Language = sms.Attribute("Language"); if (Language != null) { comSms.Language = Language.Value; } var Validated = sms.Attribute("Validated"); if (Validated != null) { comSms.Validated = Convert.ToBoolean(Validated.Value); } var DataModifica = sms.Attribute("DataModifica"); if (DataModifica != null) { comSms.DataModifica = Convert.ToDateTime(DataModifica.Value, CultureInfo.InvariantCulture); } var DataInserimento = sms.Attribute("DataInserimento"); if (DataInserimento != null) { comSms.DataInserimento = Convert.ToDateTime(DataInserimento.Value, CultureInfo.InvariantCulture); } var Produzione = sms.Attribute("Produzione"); if (Produzione != null) { comSms.Produzione = Convert.ToBoolean(Produzione.Value); } var AccettatoUsoCommerciale = sms.Attribute("AccettatoUsoCommerciale"); if (AccettatoUsoCommerciale != null) { comSms.AccettatoUsoCommerciale = Convert.ToBoolean(AccettatoUsoCommerciale.Value); } var AutorizzatoTerzeParti = sms.Attribute("AutorizzatoTerzeParti"); if (AutorizzatoTerzeParti != null) { comSms.AutorizzatoTerzeParti = Convert.ToBoolean(AutorizzatoTerzeParti.Value); } } _repoSms.Flush(); } }
public PhoneNumber(CommunicationSmsRecord record) { Prefix = record.Prefix ?? string.Empty; Number = record.Sms ?? string.Empty; }