public void SaveContact()
        {
            CustomerModel contactModel = new CustomerModel();

            List<PhoneNumberVO> numbers = _view.AdditionalContactPhoneList;

            CS_Contact contact = new CS_Contact()
            {
                Attn = _view.ContactAttn,
                Name = _view.ContactName,
                LastName = _view.ContactLastName,
                Alias = _view.ContactAlias,
                Address1 = _view.ContactAddress,
                Address2 = _view.ContactAddress2,
                State = _view.ContactState,
                City = _view.ContactCity,
                Country = _view.ContactCountry,
                Zip = _view.ContactZipcode,
                HomePhoneCodeArea = _view.ContactHomePhoneCodeArea,
                Phone = _view.ContactHomePhone,
                FaxCodeArea = _view.ContactFaxPhoneCodeArea,
                Fax = _view.ContactFaxPhone,
                Email = _view.ContactEmail,
                BillName = _view.ContactBillingName,
                BillAddress1 = _view.ContactBillingAddress,
                BillAddress2 = _view.ContactBillingAddress2,
                BillAttn = _view.ContactBillingAttn,
                BillState = _view.ContactBillingState,
                BillCity = _view.ContactBillingCity,
                BillCountry = _view.ContactBillingCountry,
                BillingHomePhoneCodeArea = _view.ContactBillingHomePhoneCodeArea,
                BillPhone = _view.ContactBillingHomePhone,
                BillFaxCodeArea = _view.ContactBillingFaxPhoneCodeArea,
                BillFax = _view.ContactBillingFaxPhone,
                BillSalutation = _view.ContactBillingSalutation,
                //BillThruProject = _view.ContactBillingThruProject,
                BillZip = _view.ContactBillingZipcode,
                CountryID = 1,
                Webpage = _view.ContactWebpage,
                IMAddress = _view.ContactIMAddress,
                DynamicsContact = _view.ContactType.Value
            };

            if (_view.ContactId.HasValue)
            {
                contact.ID = _view.ContactId.Value;
            }

            _view.SaveMessage = contactModel.SaveContact(_view.ContactCustomerID, contact, numbers, _view.UserName);

            if (_view.NewContact)
                _view.SavedContact = contact;
        }
 private void LoadContactBillinfInfo(CS_Contact selectedContact)
 {
     _view.ContactBillingName = selectedContact.BillName;
     _view.ContactBillingAddress = selectedContact.BillAddress1;
     _view.ContactBillingAddress2 = selectedContact.BillAddress2;
     _view.ContactBillingAttn = selectedContact.BillAttn;
     _view.ContactBillingState = selectedContact.BillState;
     _view.ContactBillingCity = selectedContact.BillCity;
     _view.ContactBillingCountry = selectedContact.BillCountry;
     _view.ContactBillingZipcode = selectedContact.BillZip;
     _view.ContactBillingHomePhoneCodeArea = selectedContact.BillingHomePhoneCodeArea;
     _view.ContactBillingHomePhone = selectedContact.BillingContactPhoneNumber;
     _view.ContactBillingFaxPhoneCodeArea = selectedContact.BillFaxCodeArea;
     _view.ContactBillingFaxPhone = selectedContact.BillingContactFaxPhone;
     _view.ContactBillingSalutation = selectedContact.BillSalutation;
 }
예제 #3
0
        public string SaveContact(int customerID, CS_Contact contact, List<PhoneNumberVO> numbers, string userName)
        {
            string returnMessage = "The Company Contact Profile saved successfully."; ;

            using (TransactionScope scope = new TransactionScope())
            {
                DateTime processTime = DateTime.Now;
                bool newContact = contact.ID.Equals(0);
                bool createRequest = false;
                string emailBody = string.Empty;

                //CS_Contact Insert/Update
                try
                {
                    if (!newContact)
                    {
                        returnMessage = "The Company Contact Information has been updated.";
                        Globals.CustomerMaintenance.CS_Contact_Comparer compare = new Globals.CustomerMaintenance.CS_Contact_Comparer();
                        CS_Contact oldContact = _contactRepository.Get(e => e.ID == contact.ID);

                        contact.ContactNumber = oldContact.ContactNumber;
                        contact.CheckSum = oldContact.CheckSum;
                        contact.CreatedBy = oldContact.CreatedBy;
                        contact.CreationDate = oldContact.CreationDate;
                        contact.CreationID = oldContact.CreationID;
                        contact.ModifiedBy = userName;
                        contact.ModificationDate = processTime;
                        //contact.ModificationID = ModificationID;
                        contact.Active = true;

                        emailBody = GenerateContactRequestEmailBody(contact, !newContact);
                        createRequest = !compare.Equals(oldContact, contact) && oldContact.DynamicsContact;

                        if (createRequest)
                        {
                            contact.Name = oldContact.Name;
                            contact.LastName = oldContact.LastName;
                            contact.Alias = oldContact.Alias;
                            contact.ContactNumber = oldContact.ContactNumber;
                            contact.Attn = oldContact.Attn;
                            contact.Address1 = oldContact.Address1;
                            contact.Address2 = oldContact.Address2;
                            contact.State = oldContact.State;
                            contact.City = oldContact.City;
                            contact.Country = oldContact.Country;
                            contact.Zip = oldContact.Zip;
                            contact.HomePhoneCodeArea = oldContact.HomePhoneCodeArea;
                            contact.Phone = oldContact.Phone;
                            contact.FaxCodeArea = oldContact.FaxCodeArea;
                            contact.Fax = oldContact.Fax;
                            contact.Email = oldContact.Email;
                            contact.Webpage = oldContact.Webpage;
                            contact.IMAddress = oldContact.IMAddress;
                            contact.DynamicsContact = oldContact.DynamicsContact;
                            contact.BillName = oldContact.BillName;
                            contact.BillAddress1 = oldContact.BillAddress1;
                            contact.BillAddress2 = oldContact.BillAddress2;
                            contact.BillAttn = oldContact.BillAttn;
                            contact.BillState = oldContact.BillState;
                            contact.BillCity = oldContact.BillCity;
                            contact.BillCountry = oldContact.BillCountry;
                            contact.BillZip = oldContact.BillZip;
                            contact.BillingHomePhoneCodeArea = oldContact.BillingHomePhoneCodeArea;
                            contact.BillPhone = oldContact.BillPhone;
                            contact.BillFaxCodeArea = oldContact.BillFaxCodeArea;
                            contact.BillFax = oldContact.BillFax;
                            contact.BillSalutation = oldContact.BillSalutation;
                            contact.BillThruProject = oldContact.BillThruProject;
                        }

                        contact = _contactRepository.Update(contact);
                    }
                    else
                    {
                        contact.CreatedBy = userName;
                        contact.CreationDate = processTime;
                        //contact.CreationID = CreationID;
                        contact.ModifiedBy = userName;
                        contact.ModificationDate = processTime;
                        //contact.ModificationID = ModificationID;
                        contact.Active = true;

                        contact = _contactRepository.Add(contact);

                        //CS_Customer_Contact Insert
                        CS_Customer_Contact customerContact = new CS_Customer_Contact()
                        {
                            CustomerID = customerID,
                            ContactID = contact.ID,
                            CreatedBy = contact.CreatedBy,
                            CreationDate = contact.CreationDate,
                            ModifiedBy = contact.ModifiedBy,
                            ModificationDate = contact.ModificationDate,
                            Active = contact.Active,
                            CreationID = contact.CreationID,
                            ModificationID = contact.ModificationID
                        };

                        _customerContactRepository.Add(customerContact);
                        createRequest = true && contact.DynamicsContact;
                        emailBody = GenerateContactRequestEmailBody(contact, !newContact);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Write(string.Format("An error occured while trying to save contact information.\n{0}\n{1}", ex, ex.InnerException));
                    throw new Exception("Error while trying to save contact information!", ex);
                }

                //CS_Request Insert
                if (createRequest)
                {
                    emailBody = GenerateContactRequestEmailBody(contact, !newContact);

                    SaveNewContactRequest(customerID, contact, ref emailBody);

                    if (newContact)
                        SendContactRequestEmail(emailBody, false, false, null, userName);
                    else
                        SendContactRequestEmail(emailBody, false, false, contact.ContactNumber, userName);

                    returnMessage = "A request has been sent to dynamics to create and/or update the Company Bill-To-Contact information.";
                }

                //CS_PhoneNumber Insert/Update
                try
                {
                    if (null != contact)
                    {
                        List<CS_PhoneNumber> oldPhoneList = new List<CS_PhoneNumber>();

                        if (!newContact)
                            oldPhoneList = ListAllPhonesByEmployee(contact.ID);

                        List<CS_PhoneNumber> newPhoneList = GetListFromPhoneVO(numbers);
                        List<CS_PhoneNumber> removedPhoneList = new List<CS_PhoneNumber>();

                        if (oldPhoneList.Count > 0)
                            removedPhoneList = oldPhoneList.Where(e => !newPhoneList.Any(f => f.ID == e.ID)).ToList();

                        List<CS_PhoneNumber> addedPhoneList = newPhoneList.Where(e => e.ID == 0).ToList();

                        for (int i = 0; i < removedPhoneList.Count; i++)
                        {
                            removedPhoneList[i].ModifiedBy = userName;
                            removedPhoneList[i].ModificationDate = processTime;
                            removedPhoneList[i].Active = false;
                        }

                        for (int i = 0; i < addedPhoneList.Count; i++)
                        {
                            addedPhoneList[i].ContactID = contact.ID;
                            addedPhoneList[i].CreatedBy = userName;
                            addedPhoneList[i].CreationDate = processTime;
                            //addedPhoneList[i].CreationID =
                            addedPhoneList[i].ModifiedBy = userName;
                            addedPhoneList[i].ModificationDate = processTime;
                            //addedPhoneList[i].ModificationID =
                            addedPhoneList[i].Active = true;
                        }

                        _phoneNumberRepository.UpdateList(removedPhoneList);
                        _phoneNumberRepository.AddList(addedPhoneList);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Write(string.Format("An error occured while trying to Update Additional Contact Information.\n{0}\n{1}", ex, ex.InnerException));
                    throw new Exception("Error while updating Additional Contact Information", ex);
                }

                scope.Complete();
            }

            return returnMessage;
        }
예제 #4
0
        /// <summary>
        /// Generates the email body to be sent for Contact request
        /// </summary>
        /// <param name="contact">Contact information</param>
        /// <param name="isUpdate">Indicates if it's an update or not</param>
        /// <returns>Email Body</returns>
        private string GenerateContactRequestEmailBody(CS_Contact contact, bool isUpdate)
        {
            if (null != contact)
            {
                StringBuilder emailBody = new StringBuilder();

                if (isUpdate)
                    emailBody.Append("<p>A change for an existing Company Contact record has been requested for ");
                else
                    emailBody.Append("<p>A new Company Contact record has been requested for ");
                emailBody.Append(contact.Name);
                if (isUpdate)
                {
                    emailBody.Append(" with a master ID of ");
                    emailBody.Append(contact.ContactNumber);
                    emailBody.Append(" and ");
                }
                emailBody.Append(" with a temporary ID of @@TemporaryID");

                emailBody.Append(" on ");
                emailBody.Append(DateTime.Now.ToString("MM/dd/yyyy"));
                emailBody.Append(" by ");
                emailBody.Append(contact.ModifiedBy);
                emailBody.Append(".</p>");

                emailBody.Append("<p>Please review Company Contact information");
                if (!isUpdate)
                    emailBody.Append(" and determine a master ID should be created in Dynamics.");
                emailBody.Append("</p>");

                StringBuilder contactFormattedData = new StringBuilder();
                contactFormattedData.AppendFormat("Contact Name: <Text>{0}, {1}<BL>", contact.LastName, contact.Name);
                contactFormattedData.Append("Company: <Text>");
                foreach (CS_Customer_Contact customer in contact.CS_Customer_Contact)
                    contactFormattedData.AppendFormat("{0} - {1}<BL>", customer.CS_Customer.CustomerNumber, customer.CS_Customer.Name);
                contactFormattedData.AppendFormat("Salutation: <Text>{0}<BL>", contact.BillSalutation);
                contactFormattedData.AppendFormat("Address Line 1: <Text>{0}<BL>", contact.Address1);
                contactFormattedData.AppendFormat("Address Line 2: <Text>{0}<BL>", contact.Address2);
                contactFormattedData.AppendFormat("City: <Text>{0}<BL>", contact.City);
                contactFormattedData.AppendFormat("State/Province: <Text>{0}<BL>", contact.State);
                contactFormattedData.AppendFormat("Postal Code: <Text>{0}<BL>", contact.Zip);
                contactFormattedData.AppendFormat("Country/Region: <Text>{0}<BL>", contact.Country);
                contactFormattedData.AppendFormat("Phone/Extension: <Text>{0}<BL>", contact.Phone);
                contactFormattedData.AppendFormat("Fax/Extension: <Text>{0}<BL>", contact.Fax);
                contactFormattedData.AppendFormat("Email Address: <Text>{0}<BL>", contact.Email);

                emailBody.Append(StringManipulation.TabulateString(contactFormattedData.ToString()));

                return emailBody.ToString();
            }
            else
                return string.Empty;
        }
예제 #5
0
        /// <summary>
        /// Generates the cancel email body to be sent for Contact request
        /// </summary>
        /// <param name="contact">Contact information</param>
        /// <param name="isUpdate">Indicates if it's an update or not</param>
        /// <param name="requestDate">Request date</param>
        /// <param name="requestedByUsername">Username that created the request</param>
        /// <returns>Email Body</returns>
        private string GenerateCancelContactRequestEmailBody(CS_Contact contact, bool isUpdate, DateTime requestDate, string requestedByUsername)
        {
            if (null != contact)
            {
                StringBuilder emailBody = new StringBuilder();

                if (isUpdate)
                    emailBody.Append("<p>The request to change am existing Company Contact record for ");
                else
                    emailBody.Append("<p>The request to add a new Company Contact record for ");
                emailBody.AppendFormat("{0}, {1}", contact.LastName, contact.Name);

                if (isUpdate)
                {
                    emailBody.Append(" with a master ID of ");
                    emailBody.Append(contact.ContactNumber);
                }
                else
                {
                    emailBody.Append(" with a temporary ID of ");
                    emailBody.Append(contact.ID);
                }
                emailBody.Append(" on ");
                emailBody.Append(requestDate.ToString("MM/dd/yyyy"));
                emailBody.Append(" by ");
                emailBody.Append(requestedByUsername);
                emailBody.Append(" Has been cancelled. Please disregard request.</p>");

                return emailBody.ToString();
            }
            else
                return string.Empty;
        }
예제 #6
0
        public void SaveNewContactRequest(int customerID, CS_Contact newContact, ref string note)
        {
            try
            {
                CS_Request request = new CS_Request()
                {
                    CustomerID = customerID,
                    ContactID = newContact.ID,
                    RequestDate = DateTime.Now,
                    Note = note,
                    Status = (int)Globals.CustomerMaintenance.RequestStatus.Pending,
                    ApprovedDate = null,
                    IsCustomer = false,
                    CreatedBy = newContact.ModifiedBy,
                    CreationDate = newContact.ModificationDate,
                    CreationID = newContact.ModificationID,
                    ModifiedBy = newContact.ModifiedBy,
                    ModificationDate = newContact.ModificationDate,
                    ModificationID = newContact.ModificationID,
                    Active = true
                };

                _requestRepository.Add(request);

                note = note.Replace("@@TemporaryID", newContact.ID + "-" + request.ID);
            }
            catch (Exception ex)
            {
                Logger.Write(string.Format("An error occured while trying to save contact request information.\n{0}\n{1}", ex, ex.InnerException));
                throw new Exception("Error while trying to save contact request information!", ex);
            }
        }
 void uscCustomer_CustomerContactChanged(CS_Contact customerContactEntity)
 {
     uscJobInfo.DivisionFromExternalSource = null;
 }