public void SetPhone(string prefix, string number, IUser user) { var contactpart = _communicationService.GetContactFromUser(user.Id); if (contactpart == null) // non dovrebbe mai succedere (inserito nel caso cambiassimo la logica già implementata) { _communicationService.UserToContact(user); contactpart = _communicationService.GetContactFromUser(user.Id); } if (contactpart != null) { // TODO: this method overrides previous saved number. We may want to fix that. _communicationService.AddSmsToContact(prefix, number, contactpart.ContentItem, true); } }
public void OrderToContact(OrderPart order) { // tutto in try catch perchè viene scatenato appena finito il pagamento e quindi non posso permettermi di annullare la transazione try { // recupero il contatto var currentUser = _orchardServices.WorkContext.CurrentUser; var ContactList = new List <ContentItem>(); if (currentUser != null) { var contactpart = _communicationService.GetContactFromUser(currentUser.Id); if (contactpart == null) // non dovrebbe mai succedere (inserito nel caso cambiassimo la logica già implementata) { _communicationService.UserToContact(currentUser); contactpart = _communicationService.GetContactFromUser(currentUser.Id); } ContactList.Add(contactpart.ContentItem); } else { var contacts = _communicationService.GetContactsFromMail(order.CustomerEmail); if (contacts.Count > 0) { ContactList = contacts; } else { var newcontact = _orchardServices.ContentManager.Create("CommunicationContact", VersionOptions.Draft); ((dynamic)newcontact).CommunicationContactPart.Master = false; ContactList.Add(newcontact); } } foreach (var contactItem in ContactList) { // nel caso in cui una sincro fallisce continua con try { StoreAddress(order.BillingAddress, "BillingAddress", contactItem); } catch (Exception ex) { _Logger.Error("OrderToContact -> BillingAddress -> order id= " + order.Id.ToString() + " Error: " + ex.Message); } try { StoreAddress(order.ShippingAddress, "ShippingAddress", contactItem); } catch (Exception ex) { _Logger.Error("OrderToContact -> ShippingAddress -> order id= " + order.Id.ToString() + " Error: " + ex.Message); } try { _communicationService.AddEmailToContact(order.CustomerEmail, contactItem); } catch (Exception ex) { _Logger.Error("OrderToContact -> AddEmailToContact -> order id= " + order.Id.ToString() + " Error: " + ex.Message); } try { // non sovrascrivo se dato già presente _communicationService.AddSmsToContact((order.CustomerPhone + ' ').Split(' ')[0], (order.CustomerPhone + ' ').Split(' ')[1], contactItem, false); } catch (Exception ex) { _Logger.Error("OrderToContact -> AddSmsToContact -> order id= " + order.Id.ToString() + " Error: " + ex.Message); } } } catch (Exception myex) { _Logger.Error("OrderToContact -> order id= " + order.Id.ToString() + " Error: " + myex.Message); } }