public static List <Contact_V02> GetContactsByName(string distributorID, string partialName)
 {
     using (var proxy = ServiceClientProvider.GetDistributorCRMServiceProxy())
     {
         var request = new ListContactsByNameRequest_V01();
         request.Name          = partialName;
         request.DistributorID = distributorID;
         try
         {
             var response = proxy.ListContactsByName(new ListContactsByNameRequest(request)).ListContactsByNameResult as ListContactsByNameResponse_V01;
             if (response != null && response.Status == ServiceResponseStatusType.Success)
             {
                 return(response.Contacts);
             }
             else
             {
                 return(null);
             }
         }
         catch (Exception ex)
         {
             Log(ex, proxy);
             return(null);
         }
     }
 }
        public static List <Contact_V02> GetContactsByContactListIDs(string distributorID, List <int> contactListIDs)
        {
            using (var bwService = ServiceClientProvider.GetDistributorCRMServiceProxy())
            {
                var request = new ListContactsByListIDsRequest_V01();

                request.DistributorID  = distributorID;
                request.ContactListIDs = contactListIDs;

                try
                {
                    var response = bwService.ListContactsByContactListIDs(new ListContactsByContactListIDsRequest(request)).ListContactsByContactListIDsResult as ListContactsByListIDsResponse_V01;
                    if (response != null && response.Status == ServiceResponseStatusType.Success)
                    {
                        return(response.Contacts);
                    }
                    else
                    {
                        return(null);
                    }
                }
                catch (Exception ex)
                {
                    Log(ex, bwService);
                    return(null);
                }
            }
        }
        public static bool DeleteContacts(string distributorID, List <int> contactIDs)
        {
            ExpireAllContacts(distributorID);

            var request = new DeleteContactsByIDRequest_V01 {
                ContactIDs = contactIDs, DistributorID = distributorID
            };

            using (var proxy = ServiceClientProvider.GetDistributorCRMServiceProxy())
            {
                try
                {
                    var response = proxy.DeleteContactsByID(new DeleteContactsByIDRequest(request));
                    if (response.DeleteContactsByIDResult != null && response.DeleteContactsByIDResult.Status == ServiceResponseStatusType.Success)
                    {
                        return(true);
                    }
                }
                catch (Exception ex)
                {
                    Log(ex, proxy);
                    return(false);
                }
            }

            return(false);
        }
        public static Contact_V01 SaveContact(Contact_V01 contact, string distributorID)
        {
            ExpireAllContacts(distributorID);

            var request = new SaveContactRequest_V01
            {
                Contact       = contact,
                DistributorID = distributorID,
                IsImport      = false
            };

            using (var proxy = ServiceClientProvider.GetDistributorCRMServiceProxy())
            {
                try
                {
                    var response = proxy.SaveContact(new SaveContactRequest1(request)).SaveContactResult as SaveContactResponse_V01;
                    if (response != null && response.Status == ServiceResponseStatusType.Success)
                    {
                        return(response.Contact as Contact_V01);
                    }

                    return(null);
                }
                catch (Exception ex)
                {
                    Log(ex, proxy);
                    return(null);
                }
            }
        }
        public static List <string> AddDistributorsToContacts(string distributorID,
                                                              List <string> distributorIDs,
                                                              int importMode)
        {
            ExpireAllContacts(distributorID);

            using (var proxy = ServiceClientProvider.GetDistributorCRMServiceProxy())
            {
                var request = new AddDistributorsToContactsRequest_V01();

                request.DistributorID  = distributorID;
                request.DistributorIDs = distributorIDs;
                request.ImportMode     = importMode;

                try
                {
                    var response = proxy.AddDistributorsToContacts(new AddDistributorsToContactsRequest1(request)).AddDistributorsToContactsResult as AddDistributorsToContactsResponse_V01;
                    if (response != null && response.Status == ServiceResponseStatusType.Success)
                    {
                        return(response.MissingDistributors);
                    }
                    else
                    {
                        return(null);
                    }
                }
                catch (Exception ex)
                {
                    Log(ex, proxy);
                    return(null);
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Deletes the appointments by ID.
        /// </summary>
        /// <param name="appointmentIDs">The appointment I ds.</param>
        /// <returns></returns>
        public static bool DeleteAppointmentsByID(int[] appointmentIDs)
        {
            using (var proxy = ServiceClientProvider.GetDistributorCRMServiceProxy())
            {
                try
                {
                    var iList = new List <int>();
                    iList.AddRange(appointmentIDs);

                    DeleteAppointmentsByIDRequest_V01 request01 = new DeleteAppointmentsByIDRequest_V01()
                    {
                        AppointmentIDs = iList
                    };

                    DeleteAppointmentsByIDResponse_V01 responseV01 =
                        proxy.DeleteAppointments(new DeleteAppointmentsRequest1(request01)).DeleteAppointmentsResult as DeleteAppointmentsByIDResponse_V01;

                    return(responseV01.Status == ServiceResponseStatusType.Success);
                }
                catch (Exception ex)
                {
                    Log(ex, proxy);
                    throw ex;
                }
            }
        }
        public static int?AddContactsToList(string distributorID, ContactListInfo_V01 list, List <int> contacts)
        {
            ExpireAllContacts(distributorID);

            using (var proxy = ServiceClientProvider.GetDistributorCRMServiceProxy())
            {
                var request = new AddContactsToListRequest_V01();

                request.DistributorID = distributorID;
                request.ContactIDs    = contacts;
                request.List          = list;

                try
                {
                    var response = proxy.AddContactsToList(new AddContactsToListRequest1(request)).AddContactsToListResult as AddContactsToListResponse_V01;
                    if (response != null && response.Status == ServiceResponseStatusType.Success)
                    {
                        return(response.ListID);
                    }
                    else
                    {
                        return(null);
                    }
                }
                catch (Exception ex)
                {
                    Log(ex, proxy);
                    return(null);
                }
            }
        }
        public static int?GetContactIDByContactDistributorID(string distributorID, string contactDistributorID)
        {
            using (var proxy = ServiceClientProvider.GetDistributorCRMServiceProxy())
            {
                var request = new GetContactByContactDistributorIDRequest_V01();

                request.ContactDistributorID = contactDistributorID;
                request.DistributorID        = distributorID;
                try
                {
                    var response =
                        proxy.GetContactByContactDistributorID(new GetContactByContactDistributorIDRequest(request)).GetContactByContactDistributorIDResult as GetContactByContactDistributorIDResponse_V01;
                    if (response != null && response.Status == ServiceResponseStatusType.Success)
                    {
                        return(response.ContactID);
                    }
                    else
                    {
                        throw new Exception("GetContactByContactDistributorIDResponse status is failure.");
                    }
                }
                catch (Exception ex)
                {
                    Log(ex, proxy);
                    return(null);
                }
            }
        }
        public static bool DeleteContactList(string distributorID, int contactListID)
        {
            ExpireAllContacts(distributorID);

            // TODO: verify distributor ID is owner?
            var request = new DeleteContactListRequest_V01 {
                ContactListID = contactListID
            };

            using (var proxy = ServiceClientProvider.GetDistributorCRMServiceProxy())
            {
                try
                {
                    var response = proxy.DeleteContactList(new DeleteContactListRequest1(request));
                    if (response.DeleteContactListResult != null && response.DeleteContactListResult.Status == ServiceResponseStatusType.Success)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    Log(ex, proxy);
                    return(false);
                }
            }
        }
Esempio n. 10
0
 /// <summary>
 /// Saves the appointment.
 /// </summary>
 /// <param name="distributorID">The distributor ID.</param>
 /// <param name="appointment">The appointment.</param>
 /// <param name="isNew">if set to <c>true</c> [is new].</param>
 /// <param name="saveDatesOnly">if set to <c>true</c> [save dates only].</param>
 /// <param name="bWantEntireResult">if set to true return the entire repsonse</param>
 /// <returns></returns>
 public static SaveAppointmentResponse_V01 SaveAppointment(string distributorID, Appointment_V01 appointment, bool isNew, bool saveDatesOnly, bool bWantEntireResult)
 {
     using (var proxy = ServiceClientProvider.GetDistributorCRMServiceProxy())
     {
         try
         {
             SaveAppointmentRequest_V01 request01 = new SaveAppointmentRequest_V01()
             {
                 DistributorID   = distributorID,
                 Appointment     = appointment,
                 IsNew           = isNew,
                 UpdateDatesOnly = saveDatesOnly
             };
             SaveAppointmentResponse_V01 responseV01 =
                 proxy.SaveAppointment(new SaveAppointmentRequest1(request01)).SaveAppointmentResult as SaveAppointmentResponse_V01;
             //todo: validate response, handle errors.
             return(responseV01);
         }
         catch (Exception ex)
         {
             Log(ex, proxy);
             throw ex;
         }
     }
 }
Esempio n. 11
0
        public static List <Task_V01> ListTasks(string distributorID)
        {
            using (var proxy = ServiceClientProvider.GetDistributorCRMServiceProxy())
            {
                try
                {
                    ListTasksRequest_V01 requestV01 = new ListTasksRequest_V01
                    {
                        DistributorID = distributorID,
                    };
                    ListTasksResponse_V01 responseV01 =
                        proxy.ListTasks(new ListTasksRequest1(requestV01)).ListTasksResult as ListTasksResponse_V01;
                    //todo: add exception/error handling

                    SortByDueDate(responseV01.Tasks);

                    return(responseV01.Tasks);
                }
                catch (Exception ex)
                {
                    Log(ex, proxy);
                    throw ex;
                }
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Saves the calendar settings.
        /// </summary>
        /// <param name="distributorID">The distributor ID.</param>
        /// <param name="settings">The settings.</param>
        /// <param name="isNew">if set to <c>true</c> [is new].</param>
        /// <returns></returns>
        public static int SaveCalendarSettings(string distributorID, CalendarSettings_V01 settings, bool isNew)
        {
            using (var proxy = ServiceClientProvider.GetDistributorCRMServiceProxy())
            {
                try
                {
                    SaveCalendarSettingsRequest_V01 request01 = new SaveCalendarSettingsRequest_V01()
                    {
                        DistributorID    = distributorID,
                        CalendarSettings = settings,
                        IsNew            = isNew
                    };

                    SaveCalendarSettingsResponse_V01 response01 =
                        proxy.SaveCalendarSettings(new SaveCalendarSettingsRequest1(request01)).SaveCalendarSettingsResult as SaveCalendarSettingsResponse_V01;

                    return(response01.CalendarSettingsID);
                }
                catch (Exception ex)
                {
                    Log(ex, proxy);
                    throw ex;
                }
            }
        }
        public static List <Contact_V03> GetDistributorByFilter(string distributorID, ContactFilter_V01 contactFilterV01)
        {
            var request = new ListContactsByFilterRequest_V01
            {
                ContactFilter = contactFilterV01,
                DistributorID = distributorID
            };

            using (var proxy = ServiceClientProvider.GetDistributorCRMServiceProxy())
            {
                try
                {
                    var response = proxy.ListDistributorByFilter(new ListDistributorByFilterRequest(request)).ListDistributorByFilterResult as ListContactsByOwnerResponse_V01;
                    if (response != null && response.Status == ServiceResponseStatusType.Success)
                    {
                        return(response.Contacts);
                    }
                }
                catch (Exception ex)
                {
                    Log(ex, proxy);
                    return(new List <Contact_V03>());
                }
            }

            return(new List <Contact_V03>());
        }
        public static Contact_V01 GetContactDetail(int contactID, out List <int> assignedLists)
        {
            var request = new GetContactRequest_V01 {
                ContactID = contactID
            };

            using (var proxy = ServiceClientProvider.GetDistributorCRMServiceProxy())
            {
                try
                {
                    var response = proxy.GetContact(new GetContactRequest1(request)).GetContactResult as GetContactResponse_V01;
                    if (response != null && response.Status == ServiceResponseStatusType.Success)
                    {
                        assignedLists = response.Lists;
                        return(response.Contact as Contact_V01);
                    }
                    else
                    {
                        assignedLists = null;
                        return(null);
                    }
                }
                catch (Exception ex)
                {
                    Log(ex, proxy);
                    assignedLists = null;
                    return(null);
                }
            }
        }
        private static List <Contact_V03> FilterContacts(string DistributorID,
                                                         ContactFilter_V01 contactFilter,
                                                         List <Contact_V03> allContacts)
        {
            if (contactFilter == null)
            {
                return(new List <Contact_V03>());
            }

            List <int> matchedContactIDs = null;

            if (ValidateContactFilter(contactFilter))
            {
                return(allContacts);
            }

            using (var proxy = ServiceClientProvider.GetDistributorCRMServiceProxy())
            {
                var request = new ListContactsByFilterRequest_V01();

                request.DistributorID = DistributorID;
                request.ContactFilter = contactFilter;

                var response = proxy.ListContactsByFilter(new ListContactsByFilterRequest(request)).ListContactsByFilterResult as ListContactsByFilterResponse_V01;
                if (response != null && response.Status == ServiceResponseStatusType.Success)
                {
                    matchedContactIDs = response.ContactIDs;
                }
                else
                {
                    return(null);
                }
            }

            if (allContacts == null)
            {
                return(null);
            }

            if (matchedContactIDs.Count == 0)
            {
                return(new List <Contact_V03>());
            }

            var result = new List <Contact_V03>();

            var filteredContacts = allContacts.Where(contact => matchedContactIDs.Contains(contact.ContactID));

            if (null != filteredContacts && filteredContacts.Count() > 0)
            {
                result = filteredContacts.ToList();
            }

            return(result);
        }
Esempio n. 16
0
        public static void SaveTasksStatusByIDs(TaskStatusType newStatus, List <int> taskIDs)
        {
            using (var proxy = ServiceClientProvider.GetDistributorCRMServiceProxy())
            {
                try
                {
                    SaveTasksStatusRequest_V01 request = new SaveTasksStatusRequest_V01();
                    request.TaskIDs   = taskIDs;
                    request.NewStatus = newStatus;

                    SaveTasksStatusResponse_V01 response = proxy.SaveTasksStatus(new SaveTasksStatusRequest(request)).SaveTasksStatusResult as SaveTasksStatusResponse_V01;
                }
                catch (Exception ex)
                {
                    Log(ex, proxy);
                }
            }
        }
Esempio n. 17
0
        public static void DeleteTasksByID(string DistributorID, List <int> taskIDs)
        {
            using (var proxy = ServiceClientProvider.GetDistributorCRMServiceProxy())
            {
                try
                {
                    DeleteTasksByIDRequest_V01 request = new DeleteTasksByIDRequest_V01();
                    request.TaskIDs = taskIDs;

                    DeleteTasksByIDResponse_V01 response = proxy.DeleteTasks(new DeleteTasksRequest(request)).DeleteTasksResult as DeleteTasksByIDResponse_V01;
                }
                catch (Exception ex)
                {
                    Log(ex, proxy);
                    throw ex;
                }
            }
        }
Esempio n. 18
0
        public static Task_V01 GetTaskByID(int taskID)
        {
            using (var proxy = ServiceClientProvider.GetDistributorCRMServiceProxy())
            {
                try
                {
                    GetTaskByIDRequest_V01 request01 = new GetTaskByIDRequest_V01()
                    {
                        TaskID = taskID
                    };

                    GetTaskByIDResponse_V01 responseV01 = proxy.GetTask(new GetTaskRequest1(request01)).GetTaskResult as GetTaskByIDResponse_V01;

                    return(responseV01.Task);
                }
                catch (Exception ex)
                {
                    Log(ex, proxy);
                    throw ex;
                }
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Gets the appointment by ID.
        /// </summary>
        /// <param name="appointmentID">The appointment ID.</param>
        /// <returns></returns>
        public static Appointment_V01 GetAppointmentByID(int appointmentID)
        {
            using (var proxy = ServiceClientProvider.GetDistributorCRMServiceProxy())
            {
                try
                {
                    GetAppointmentByIDRequest_V01 request01 = new GetAppointmentByIDRequest_V01()
                    {
                        AppointmentID = appointmentID
                    };

                    GetAppointmentByIDResponse_V01 responseV01 = proxy.GetAppointment(new GetAppointmentRequest1(request01)).GetAppointmentResult as GetAppointmentByIDResponse_V01;

                    return(responseV01.Appointment);
                }
                catch (Exception ex)
                {
                    Log(ex, proxy);
                    throw ex;
                }
            }
        }
        public static List <ContactListInfo_V01> GetContactListsByOwner(string distributorID, bool RetrieveCount)
        {
            try
            {
                return(SimpleCache.Retrieve(
                           delegate
                {
                    using (var proxy = ServiceClientProvider.GetDistributorCRMServiceProxy())
                    {
                        var request = new ListContactListsByOwnerRequest_V01();

                        request.DistributorID = distributorID;
                        request.RetrieveCount = RetrieveCount;

                        var response =
                            proxy.ListContactListsByOwner(new ListContactListsByOwnerRequest(request)).ListContactListsByOwnerResult as ListContactListsByOwnerResponse_V01;
                        if (response != null && response.Status == ServiceResponseStatusType.Success)
                        {
                            return response.Lists;
                        }
                        else
                        {
                            return null;
                        }
                    }
                },
                           GetContactListCacheKey(distributorID, RetrieveCount), DefaultSimpleCacheDuration));
            }
            catch (Exception ex)
            {
                Log(
                    new ApplicationException(
                        "Error retrieving contact list in GetContactListssByOwner. DistributorID: " + distributorID, ex));

                ExpireAllContacts(distributorID);
                return(null);
            }
        }
        public static void UpdateContactList(int contactListID, string distributorID, string name, List <int> contactIDs)
        {
            ExpireAllContacts(distributorID);

            using (var bwService = ServiceClientProvider.GetDistributorCRMServiceProxy())
            {
                var request = new SaveContactListRequest_V01();

                request.DistributorID = distributorID;
                request.Name          = name;
                request.ContactIDs    = contactIDs;
                request.ContactListID = contactListID;

                try
                {
                    var response = bwService.SaveContactList(new SaveContactListRequest1(request)).SaveContactListResult as SaveContactListResponse_V01;
                }
                catch (Exception ex)
                {
                    Log(ex, bwService);
                }
            }
        }
Esempio n. 22
0
 /// <summary>
 /// Lists the appointments.
 /// </summary>
 /// <param name="distributorID">The distributor ID.</param>
 /// <param name="startDate">The start date.</param>
 /// <param name="endDate">The end date.</param>
 /// <returns></returns>
 public static List <Appointment_V01> ListAppointments(string distributorID, DateTime startDate, DateTime endDate)
 {
     using (var proxy = ServiceClientProvider.GetDistributorCRMServiceProxy())
     {
         try
         {
             ListAppointmentsByDateRequest_V01 requestV01 = new ListAppointmentsByDateRequest_V01
             {
                 DistributorID = distributorID,
                 StartDate     = startDate,
                 EndDate       = endDate
             };
             ListAppointmentsResponse_V01 responseV01 =
                 proxy.ListAppointments(new ListAppointmentsRequest1(requestV01)).ListAppointmentsResult as ListAppointmentsResponse_V01;
             //todo: add exception/error handling
             return(responseV01.Appointments);
         }
         catch (Exception ex)
         {
             Log(ex, proxy);
             throw ex;
         }
     }
 }
Esempio n. 23
0
 public static int SaveTask(string distributorID, Task_V01 task, bool isNew)
 {
     using (var proxy = ServiceClientProvider.GetDistributorCRMServiceProxy())
     {
         try
         {
             SaveTaskRequest_V01 request01 = new SaveTaskRequest_V01()
             {
                 DistributorID = distributorID,
                 Task          = task,
                 IsNew         = isNew,
             };
             SaveTaskResponse_V01 responseV01 =
                 proxy.SaveTask(new SaveTaskRequest1(request01)).SaveTaskResult as SaveTaskResponse_V01;
             //todo: validate response, handle errors.
             return(responseV01.TaskID);
         }
         catch (Exception ex)
         {
             Log(ex, proxy);
             throw ex;
         }
     }
 }
        public static int?CopyContactList(string distributorID, int sourceContactListID, string newListName)
        {
            if (sourceContactListID == 0)
            {
                return(null);
            }

            ExpireAllContacts(distributorID);

            using (var proxy = ServiceClientProvider.GetDistributorCRMServiceProxy())
            {
                var request = new CopyContactListRequest_V01();

                request.DistributorID = distributorID;
                request.Name          = newListName;
                request.SourceListID  = sourceContactListID;

                try
                {
                    var response = proxy.CopyContactList(new CopyContactListRequest1(request)).CopyContactListResult as CopyContactListResponse_V01;
                    if (response != null && response.Status == ServiceResponseStatusType.Success)
                    {
                        return(response.ListID);
                    }
                    else
                    {
                        return(null);
                    }
                }
                catch (Exception ex)
                {
                    Log(ex, proxy);
                    return(null);
                }
            }
        }
Esempio n. 25
0
        /// <summary>
        /// Gets the calendar settings by owner.
        /// </summary>
        /// <param name="distributorID">The distributor ID.</param>
        /// <returns></returns>
        public static CalendarSettings_V01 GetCalendarSettingsByOwner(string distributorID)
        {
            using (var proxy = ServiceClientProvider.GetDistributorCRMServiceProxy())
            {
                try
                {
                    var request01 = new GetCalendarSettingsRequest_V01()
                    {
                        DistributorID = distributorID
                    };


                    var response01 =
                        proxy.GetCalendarSettingsByOwner(new GetCalendarSettingsByOwnerRequest(request01)).GetCalendarSettingsByOwnerResult as GetCalendarSettingsResponse_V01;

                    return(response01.CalendarSettings);
                }
                catch (Exception ex)
                {
                    Log(ex, proxy);
                    throw ex;
                }
            }
        }
        /// <summary>
        ///     Save contact confirmation email
        /// </summary>
        /// <param name="contact">Contact saved</param>
        /// <param name="distributorId">Name of the owner of the site</param>
        /// ///
        /// <param name="extension">Website extension</param>
        /// ///
        /// <param name="locale">Customer locale</param>
        /// ///
        /// <param name="domain">Domain for this locale</param>
        /// ///
        /// <param name="primaryLocale"></param>
        /// <param name="registrationSource">Where did the customer got the invitation</param>
        /// <param name="distributorName"></param>
        /// <param name="distributorEmail"></param>
        /// <param name="isDistributorCopied"></param>
        /// <returns>True if success</returns>
        public static bool SendContactConfirmationEmail(
            Contact_V01 contact,
            string distributorId,
            string extension,
            string locale,
            string domain,
            String distributorName,
            String distributorEmail,
            Boolean isDistributorCopied,
            String primaryLocale,
            RegistrationSource registrationSource = RegistrationSource.Other
            )
        {
            if (contact.EmailAddresses.Count < 1)
            {
                throw new ArgumentException("Argument can not be null", "Contact Email");
            }

            if (contact.LocalName == null)
            {
                throw new ArgumentException("Argument can not be null", "Contact Name");
            }

            if (string.IsNullOrEmpty(contact.DistributorID))
            {
                throw new ArgumentException("Argument can not be null", "Distributor ID");
            }

            var request = new TriggeredSendRequestRequest_V01();

            request.Data = new TriggeredSaveContactConformationSendData_V01
            {
                CustomerEmail       = contact.EmailAddresses[0].Address,
                CustomerName        = contact.LocalName,
                CustomerPhoneNumber =
                    (contact.Phones.Count > 0) ? contact.Phones.FirstOrDefault().Number : String.Empty,
                DistributorEmail    = distributorEmail,
                DistributorId       = distributorId,
                DistributorName     = distributorName,
                DataKey             = Guid.NewGuid().ToString(),
                Locale              = primaryLocale,
                Extension           = extension,
                IsDistributorCopied = isDistributorCopied,
                Domain              = domain,
                RegistrationSource  = registrationSource,
                EmailLanguageLocale = locale
            };

            using (var proxy = ServiceClientProvider.GetDistributorCRMServiceProxy())
            {
                try
                {
                    var response = proxy.SendTriggeredMessage(new SendTriggeredMessageRequest(request));
                    return(response.SendTriggeredMessageResult.Status == ServiceResponseStatusType.Success);
                }
                catch (Exception ex)
                {
                    Log(ex, proxy);
                    return(false);
                }
            }
        }