public void TestUpdateCustomer()
        {
            CS_Country countryAdded = CountryDao.Singleton.Add(new CS_Country
            {
                Name = "Country1",
                CreatedBy = "Load",
                CreationDate = DateTime.Now,
                ModificationDate = DateTime.Now,
                ModifiedBy = "Load",
                Active = true
            }
               );

            CS_Customer customerAdded = CustomerDao.Singleton.Add(new CS_Customer
            {
                CustomerNumber = null,
                Name = null,
                Address1 = null,
                Address2 = null,
                State = null,
                City = null,
                Country = null,
                Zip = null,
                Phone = null,
                Fax = null,
                Email = null,
                BillName = null,
                BillAddress1 = null,
                BillAddress2 = null,
                BillAttn = null,
                BillState = null,
                BillCity = null,
                BillCountry = null,
                BillPhone = null,
                BillFax = null,
                BillSalutation = null,
                BillThruProject = null,
                BillZip = null,
                CountryID = countryAdded.ID,
                Xml = null,
                CreatedBy = "Load",
                CreationDate = DateTime.Now,
                ModifiedBy = "Load",
                ModificationDate = DateTime.Now,
                Active = true
            }
            );

            Guid randomValue = Guid.NewGuid();

            CS_Customer customerUpdated = new CS_Customer()
            {
                ID=customerAdded.ID,
                CustomerNumber = randomValue.ToString(),
                Name = null,
                Address1 = null,
                Address2 = null,
                State = null,
                City = null,
                Country = null,
                Zip = null,
                Phone = null,
                Fax = null,
                Email = null,
                BillName = null,
                BillAddress1 = null,
                BillAddress2 = null,
                BillAttn = null,
                BillState = null,
                BillCity = null,
                BillCountry = null,
                BillPhone = null,
                BillFax = null,
                BillSalutation = null,
                BillThruProject = null,
                BillZip = null,
                CountryID = countryAdded.ID,
                Xml = null,
                CreatedBy = "Load",
                CreationDate = DateTime.Now,
                ModifiedBy = "Load",
                ModificationDate = DateTime.Now,
                Active = true
            };

            CS_Customer customerAfterUpdate = CustomerDao.Singleton.Update(customerUpdated);
            Assert.AreEqual(randomValue.ToString(), customerAfterUpdate.CustomerNumber);
        }
 /// <summary>
 /// Test the Get Method from DAO
 /// </summary>
 //[TestMethod] TODO:Fix Customer table in OneSourceTest to run this test
 public void TestGetCustomerMethodReturn()
 {
     _foundCustomer = CustomerDao.Singleton.Get(1);
     Assert.AreEqual(CONSULTING_ID, _foundCustomer.ID);
 }
 private void LoadCustomerBillingInformation(CS_Customer selectedCustomer)
 {
     _view.CustomerBillingName = selectedCustomer.BillName;
     _view.CustomerBillingAddress1 = selectedCustomer.BillAddress1;
     _view.CustomerBillingAddress2 = selectedCustomer.BillAddress2;
     _view.CustomerBillingAttn = selectedCustomer.BillAttn;
     _view.CustomerBillingState = selectedCustomer.BillState;
     _view.CustomerBillingCity = selectedCustomer.BillCity;
     _view.CustomerBillingCountry = selectedCustomer.BillCountry;
     _view.CustomerBillingZipCode = selectedCustomer.BillZip;
     _view.CustomerBillingHomePhoneAreaCode = selectedCustomer.BillingHomePhoneCodeArea;
     _view.CustomerBillingHomePhone = selectedCustomer.BillingCustomerPhoneNumberEdited;
     _view.CustomerBillingFaxPhoneCodeArea = selectedCustomer.BillFaxCodeArea;
     _view.CustomerBillingFaxPhone = selectedCustomer.BillingCustomerFaxNumberEdited;
     _view.CustomerBillingSalutation = selectedCustomer.BillSalutation;
 }
        public void SetCallLogViewCallEntryRowData()
        {
            //Arrange
            FakeObjectSet<CS_FirstAlert> fakeFirstAlert = new FakeObjectSet<CS_FirstAlert>();

            CS_FirstAlertType csFirstAlertType = new CS_FirstAlertType()
            {
                Active = true,
                Description = "injury",
                CreatedBy = "dcecilia",
                CreationDate = new DateTime(10, 10, 10, 5, 0, 1),
                ModifiedBy = "dcecilia",
                ModificationDate = new DateTime(10, 10, 10, 5, 0, 1),

            };

            CS_FirstAlertFirstAlertType csFirstAlertFirstAlertType = new CS_FirstAlertFirstAlertType()
            {
                Active = true,
                FirstAlertID = 1,
                FirstAlertTypeID = 1,
                CreatedBy = "dcecilia",
                CreationDate =
                    new DateTime(10, 10, 10, 5, 0, 1),
                ModifiedBy = "dcecilia",
                ModificationDate =
                    new DateTime(10, 10, 10, 5, 0, 1),
                CS_FirstAlertType = csFirstAlertType
            };

            EntityCollection<CS_FirstAlertFirstAlertType> entityCollectionFirstAlertFirstAlertType = new EntityCollection<CS_FirstAlertFirstAlertType>();
            entityCollectionFirstAlertFirstAlertType.Add(csFirstAlertFirstAlertType);

            DateTime currentDate = DateTime.Now;

            CS_Customer csCustomer = new CS_Customer()
                                         {
                                             ID = 1,
                                             Active = true,
                                             Name = "Abcd",
                                             Country = "USA",
                                             CustomerNumber = "1000"
                                         };

            CS_Job csJob = new CS_Job()
                               {
                                   ID = 1,
                                   Active = true,
                                   CreatedBy = "dcecilia",
                                   CreationDate = currentDate,
                                   ModifiedBy = "dcecilia",
                                   ModificationDate = currentDate,
                                   Number = "123"
                               };

            CS_FirstAlert csFirstAlert = new CS_FirstAlert()
                                             {
                                                 ID = 1,
                                                 Active = true,
                                                 Number = "123",
                                                 JobID = 1,
                                                 CS_Job = csJob,
                                                 CustomerID = 1,
                                                 CS_Customer = csCustomer,

                                                 Details = "aaAaA",
                                                 Date = currentDate,
                                                 HasPoliceReport = true,
                                                 CreatedBy = "dcecilia",
                                                 CreationDate = currentDate,
                                                 ModifiedBy = "dcecilia",
                                                 ModificationDate = new DateTime(2011, 7, 12, 5, 0, 0),
                                                 CS_FirstAlertFirstAlertType = entityCollectionFirstAlertFirstAlertType,
                                             };

            CS_Division csDivision = new CS_Division()
            {
                Active = true,
                ID = 1,
                Name = "001"
            };

            CS_FirstAlertDivision csFirstAlertDivision = new CS_FirstAlertDivision()
            {
                Active = true,
                ID = 1,
                FirstAlertID = 1,
                DivisionID = 1,
                CS_Division = csDivision,
                CS_FirstAlert = csFirstAlert
            };

            Mock<IFirstAlertView> mock = new Mock<IFirstAlertView>();
            mock.SetupProperty(c => c.FirstAlertRowDataItem, csFirstAlert);
            mock.SetupProperty(c => c.FirstAlertRowAlertDateAndTime, "");
            mock.SetupProperty(c => c.FirstAlertRowAlertId, "");
            mock.SetupProperty(c => c.FirstAlertRowAlertNumber, "");
            mock.SetupProperty(c => c.FirstAlertRowCustomer, "");
            mock.SetupProperty(c => c.FirstAlertRowDivision, "");
            mock.SetupProperty(c => c.FirstAlertRowFirstAlertType, "");
            mock.SetupProperty(c => c.FirstAlertRowJobNumber, "");

               //Act
            FirstAlertViewModel viewModel = new FirstAlertViewModel(mock.Object);

            viewModel.SetDetailedFirstAlertRowData();

            // Assert
            Assert.AreEqual(currentDate.ToString("MM/dd/yyyy") + " " + currentDate.ToShortTimeString(), mock.Object.FirstAlertRowAlertDateAndTime, "Failed in FirstAlertRowAlertDateAndTime");
            Assert.AreEqual("1", mock.Object.FirstAlertRowAlertId, "Failed in FirstAlertRowAlertId");
            Assert.AreEqual("123", mock.Object.FirstAlertRowAlertNumber, "Failed in FirstAlertRowAlertNumber");
            Assert.AreEqual("Abcd - USA - 1000", mock.Object.FirstAlertRowCustomer, "Failed in FirstAlertRowCustomer");
            Assert.AreEqual("001", mock.Object.FirstAlertRowDivision, "Failed in FirstAlertRowDivision");
            Assert.AreEqual("injury", mock.Object.FirstAlertRowFirstAlertType, "Failed in FirstAlertRowFirstAlertType");
            Assert.AreEqual("123", mock.Object.FirstAlertRowJobNumber, "Failed in FirstAlertRowJobNumber");
        }
        public void SaveCustomer()
        {
            CustomerModel customerModel = new CustomerModel();

            CS_Customer customer = new CS_Customer()
            {
                Attn = _view.CustomerAttn,
                Name = _view.CustomerName,
                Address1 = _view.CustomerAddress1,
                Address2 = _view.CustomerAddress2,
                State = _view.CustomerState,
                City = _view.CustomerCity,
                Country = _view.CustomerCountry,
                Zip = _view.CustomerZipCode,
                HomePhoneCodeArea = _view.CustomerHomePhoneCodeArea,
                Phone = _view.CustomerHomePhone,
                FaxCodeArea = _view.CustomerFaxPhoneAreaCode,
                Fax = _view.CustomerFaxPhone,
                Email = _view.CustomerEmail,
                BillName = _view.CustomerBillingName,
                BillAddress1 = _view.CustomerBillingAddress1,
                BillAddress2 = _view.CustomerBillingAddress2,
                BillAttn = _view.CustomerBillingAttn,
                BillState = _view.CustomerBillingState,
                BillCity = _view.CustomerBillingCity,
                BillCountry = _view.CustomerBillingCountry,
                BillingHomePhoneCodeArea = _view.CustomerBillingHomePhoneAreaCode,
                BillPhone = _view.CustomerBillingHomePhone,
                BillFaxCodeArea = _view.CustomerBillingFaxPhoneCodeArea,
                BillFax = _view.CustomerBillingFaxPhone,
                BillSalutation = _view.CustomerBillingSalutation,
                BillThruProject = _view.CustomerThruProject,
                BillZip = _view.CustomerBillingZipCode,
                AlertNotification = _view.CustomerAlertNotification,
                OperatorAlert = _view.CustomerOperatorAlert,
                CreditCheck = _view.CustomerCreditCheck,
                IMAddress = _view.CustomerIMAddress,
                Webpage = _view.CustomerWebpage,
                CountryID = 1,
                IsGeneralLog = false,
                CreatedBy = _view.UserName,
                CreationDate = DateTime.Now,
                ModifiedBy = _view.UserName,
                ModificationDate = DateTime.Now,
                Active = true,
                IsCollection = _view.CustomerCollection

            };

            if (_view.CustomerID.HasValue)
            {
                customer.ID = _view.CustomerID.Value;
            }

            _view.SaveMessage = customerModel.SaveCustomer(customer, _view.selectedCustomerSpecificInfoType,_view.UserName);

            if (_view.NewCustomer)
                _view.SavedCustomer = customer;
        }
        protected void actCustomer_TextChanged(object sender, EventArgs e)
        {
            actEIC.ContextKey = actCustomer.SelectedValue;
            actEIC.FilterId = actCustomer.SelectedValue;

            //actAdditionalContact.ContextKey = actCustomer.SelectedValue;
            //actAdditionalContact.FilterId = actCustomer.SelectedValue;

            actBillToContact.ContextKey = actCustomer.SelectedValue;
            actBillToContact.FilterId = actCustomer.SelectedValue;

            actCustomerContact.ContextKey = actCustomer.SelectedValue;
            actCustomerContact.FilterId = actCustomer.SelectedValue;

            if (hidContext.Value != actCustomer.SelectedValue)
            {
                actEIC.SelectedText = "";
                actEIC.SelectedValue = "0";

                actAdditionalContact.SelectedText = "";
                actAdditionalContact.SelectedValue = "0";

                actBillToContact.SelectedText = "";
                actBillToContact.SelectedValue = "0";

                actCustomerContact.SelectedText = "";
                actCustomerContact.SelectedValue = "0";

                hidContext.Value = actCustomer.SelectedValue;
            }

            if (CustomerChanged != null)
            {
                CS_Customer selectedCustomer = new CS_Customer();
                selectedCustomer.ID = int.Parse(actCustomer.SelectedValue);
                selectedCustomer.Name = actCustomer.SelectedText;
                CustomerChanged(selectedCustomer);
            }
        }
        /// <summary>
        /// Generates the cancel email body to be sent for Customer request
        /// </summary>
        /// <param name="customer">Customer 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 GenerateCancelCustomerRequestEmailBody(CS_Customer customer, bool isUpdate, DateTime requestDate, string requestedByUsername)
        {
            if (null != customer)
            {
                StringBuilder emailBody = new StringBuilder();

                if (isUpdate)
                    emailBody.Append("<p>The request to change an existing Company record for ");
                else
                    emailBody.Append("<p>The request to add a new Company record for ");
                emailBody.Append(customer.Name);
                if (isUpdate)
                {
                    emailBody.Append(" with a Master ID of ");
                    emailBody.Append(customer.CustomerNumber);
                }
                else
                {
                    emailBody.Append(" with a temporary ID of ");
                    emailBody.Append(customer.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;
        }
        /// <summary>
        /// Generates the email body to be sent for Customer request
        /// </summary>
        /// <param name="customer">Customer information</param>
        /// <param name="isUpdate">Indicates if it's an update or not</param>
        /// <returns>Email Body</returns>
        private string GenerateCustomerRequestEmailBody(CS_Customer customer, bool isUpdate)
        {
            if (null != customer)
            {
                StringBuilder emailBody = new StringBuilder();

                if (isUpdate)
                    emailBody.Append("<p>A change for an existing Company record has been requested for ");
                else
                    emailBody.Append("<p>A new Company record has been requested for ");
                emailBody.Append(customer.Name);
                if (isUpdate)
                {
                    emailBody.Append(" with a master ID of ");
                    emailBody.Append(customer.CustomerNumber);
                    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(customer.ModifiedBy);
                emailBody.Append(".</p>");

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

                StringBuilder customerFormattedData = new StringBuilder();
                customerFormattedData.AppendFormat("Company: <Text>{0}<BL>", customer.Name);
                customerFormattedData.AppendFormat("Bill-To-Contact: <Text>{0}<BL>", customer.BillName);
                customerFormattedData.AppendFormat("Attention: <Text>{0}<BL>", customer.Attn);
                customerFormattedData.AppendFormat("Salutation: <Text>{0}<BL>", customer.BillSalutation);
                customerFormattedData.AppendFormat("Address Line 1: <Text>{0}<BL>", customer.Address1);
                customerFormattedData.AppendFormat("Address Line 2: <Text>{0}<BL>", customer.Address2);
                customerFormattedData.AppendFormat("City: <Text>{0}<BL>", customer.City);
                customerFormattedData.AppendFormat("State/Province: <Text>{0}<BL>", customer.State);
                customerFormattedData.AppendFormat("Postal Code: <Text>{0}<BL>", customer.Zip);
                customerFormattedData.AppendFormat("Country/Region: <Text>{0}<BL>", customer.Country);
                customerFormattedData.AppendFormat("Phone/Extension: <Text>{0}<BL>", customer.Phone);
                customerFormattedData.AppendFormat("Fax/Extension: <Text>{0}<BL>", customer.Fax);
                customerFormattedData.AppendFormat("Email Address: <Text>{0}<BL>", customer.Email);

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

                return emailBody.ToString();
            }
            else
                return string.Empty;
        }
        public string UpdateCustomer(CS_Customer newCustomer, IList<int> selectedCustomerSpecificInfoType, string userName)
        {
            try
            {
                Globals.CustomerMaintenance.CS_Customer_Comparer comparer = new Globals.CustomerMaintenance.CS_Customer_Comparer();
                CS_Customer oldCustomer = _customerRepository.Get(e => e.ID == newCustomer.ID);
                string returnMessage = "The Company Profile has been updated.";

                if (null != oldCustomer)
                {
                    CS_Customer updateCustomer = new CS_Customer()
                       {
                           ID = oldCustomer.ID,
                           Attn = oldCustomer.Attn,
                           CustomerNumber = oldCustomer.CustomerNumber,
                           Name = oldCustomer.Name,
                           Address1 = oldCustomer.Address1,
                           Address2 = oldCustomer.Address2,
                           State = oldCustomer.State,
                           City = oldCustomer.City,
                           Country = oldCustomer.Country,
                           Zip = oldCustomer.Zip,
                           Phone = newCustomer.Phone,
                           HomePhoneCodeArea = oldCustomer.HomePhoneCodeArea,
                           Fax = newCustomer.Fax,
                           FaxCodeArea = oldCustomer.FaxCodeArea,
                           Email = oldCustomer.Email,
                           BillName = oldCustomer.BillName,
                           BillAddress1 = oldCustomer.BillAddress1,
                           BillAddress2 = oldCustomer.BillAddress2,
                           BillAttn = oldCustomer.BillAttn,
                           BillState = oldCustomer.BillState,
                           BillCity = oldCustomer.BillCity,
                           BillCountry = oldCustomer.BillCountry,
                           BillPhone = newCustomer.BillPhone,
                           BillingHomePhoneCodeArea = oldCustomer.BillingHomePhoneCodeArea,
                           BillFax = newCustomer.BillFax,
                           BillFaxCodeArea = oldCustomer.BillFaxCodeArea,
                           BillSalutation = oldCustomer.BillSalutation,
                           BillThruProject = oldCustomer.BillThruProject,
                           BillZip = oldCustomer.BillZip,
                           CountryID = oldCustomer.CountryID,
                           Webpage = oldCustomer.Webpage,
                           IMAddress = oldCustomer.IMAddress,
                           AlertNotification = newCustomer.AlertNotification,
                           OperatorAlert = newCustomer.OperatorAlert,
                           CreditCheck = newCustomer.CreditCheck,
                           Checksum = oldCustomer.Checksum,
                           IsGeneralLog = oldCustomer.IsGeneralLog,
                           CreatedBy = oldCustomer.CreatedBy,
                           CreationDate = oldCustomer.CreationDate,
                           ModifiedBy = userName,
                           ModificationDate = DateTime.Now,
                           Active = oldCustomer.Active,
                           IsCollection = newCustomer.IsCollection
                       };

                    DynamicFieldsAggregator aggregator = CreateAggregatorForSpecificCustomerInfo(selectedCustomerSpecificInfoType);

                    if (aggregator.Controls.Count > 0)
                        updateCustomer.Xml = GetXmlFromAggregator(aggregator);

                    _customerRepository.Update(updateCustomer);

                    if (!comparer.Equals(oldCustomer, newCustomer))
                    {
                        string emailBody = GenerateCustomerRequestEmailBody(newCustomer, true);
                        SaveNewCustomerRequest(updateCustomer, ref emailBody);
                        SendCustomerRequestEmail(emailBody, false, false, oldCustomer.CustomerNumber, userName);
                        returnMessage = "A request has been sent to dynamics to create and/or update the Company Information.";
                    }
                }

                return returnMessage;
            }
            catch (Exception ex)
            {
                Logger.Write(string.Format("An error occured while trying to update customer information.\n{0}\n{1}", ex, ex.InnerException));
                throw new Exception("Error while trying to update company information!", ex);
            }
        }
        public void SaveNewCustomerRequest(CS_Customer newCustomer, ref string note)
        {
            try
            {
                CS_Request request = new CS_Request()
                {
                    CustomerID = newCustomer.ID,
                    RequestDate = DateTime.Now,
                    Note = note,
                    Status = (int)Globals.CustomerMaintenance.RequestStatus.Pending,
                    ApprovedDate = null,
                    IsCustomer = true,
                    CreatedBy = newCustomer.ModifiedBy,
                    CreationDate = newCustomer.ModificationDate,
                    CreationID = newCustomer.ModificationID,
                    ModifiedBy = newCustomer.ModifiedBy,
                    ModificationDate = newCustomer.ModificationDate,
                    ModificationID = newCustomer.ModificationID,
                    Active = true
                };

                _requestRepository.Add(request);

                note = note.Replace("@@TemporaryID", newCustomer.ID.ToString() + "-" + request.ID.ToString());

                request.Note = note;
                _requestRepository.Update(request);
            }
            catch (Exception ex)
            {
                Logger.Write(string.Format("An error occured while trying to save customer request information.\n{0}\n{1}", ex, ex.InnerException));
                throw new Exception("Error while trying to save company request information!", ex);
            }
        }
        public void SaveNewCustomer(CS_Customer newCustomer, IList<int> selectedCustomerSpecificInfoType, string userName)
        {
            try
            {
                if (null != newCustomer)
                {
                    DynamicFieldsAggregator aggregator = CreateAggregatorForSpecificCustomerInfo(selectedCustomerSpecificInfoType);

                    if (aggregator.Controls.Count > 0)
                        newCustomer.Xml = GetXmlFromAggregator(aggregator);

                    newCustomer = _customerRepository.Add(newCustomer);

                    string emailBody = GenerateCustomerRequestEmailBody(newCustomer, false);

                    SaveNewCustomerRequest(newCustomer, ref emailBody);

                    SendCustomerRequestEmail(emailBody, false, false, null, userName);
                }
            }
            catch (Exception ex)
            {
                Logger.Write(string.Format("An error occured while trying to save customer information.\n{0}\n{1}", ex, ex.InnerException));
                throw new Exception("Error while trying to save company information!", ex);
            }
        }
        public string SaveCustomer(CS_Customer newCustomer, IList<int> selectedCustomerSpecificInfoType, string userName)
        {
            try
            {
                string returnMessage = "Company Profile saved successfully.";

                using (TransactionScope scope = new TransactionScope())
                {
                    if (newCustomer.ID == 0)
                    {
                        SaveNewCustomer(newCustomer, selectedCustomerSpecificInfoType, userName);
                    }
                    else
                    {
                        returnMessage = UpdateCustomer(newCustomer, selectedCustomerSpecificInfoType, userName);
                    }

                    scope.Complete();
                }

                return returnMessage;
            }
            catch (Exception ex)
            {
                Logger.Write(string.Format("An error occured while trying to save customer information.\n{0}\n{1}", ex, ex.InnerException));
                throw new Exception("Error while trying to save company information!", ex);
            }
        }
 protected void uscCustomer_CustomerChanged(CS_Customer customerEntity)
 {
     uscJobInfo.CustomerFromExternalSource = customerEntity;
 }