public void GenerateEmailBodyForInvoicingTeamTest()
        {
            DateTime dt = new DateTime(2011, 02, 14);

            TimeSpan timeSpan = new TimeSpan(10, 11, 59);

            CS_Country country = new CS_Country()
                                     {
                                         ID = 1,
                                         Active = true,
                                         Name = "USA"

                                     };

            CS_State state = new CS_State()
                                 {
                                     ID = 1,
                                     Active = true,
                                     Name = "Texas"
                                 };

            CS_City city = new CS_City()
                               {
                                   ID = 1,
                                   Active = true,
                                   Name = "Dalton"
                               };

            CS_LocationInfo locationInfo = new CS_LocationInfo()
                                            {
                                                Active = true,
                                                CountryID = 1,
                                                StateID = 1,
                                                CityID = 1,
                                                CS_Country = country,
                                                CS_State = state,
                                                CS_City = city
                                            };

            CS_Frequency frequency = new CS_Frequency()
                                         {
                                             Active = true,
                                             ID = 1,
                                             Description = "D"
                                         };

            CS_JobDescription csJobDescription = new CS_JobDescription()
            {
                Active = true,
                NumberEmpties = 1,
                NumberLoads = 2,
                NumberEngines = 1
            };

            CS_Division division = new CS_Division()
            {
                ID = 241,
                Active = true,
                Name = "005",
                Description = "White River, Ontario"
            };

            CS_JobDivision jobdivision = new CS_JobDivision()
            {
                Active = true,
                JobID = 243,
                DivisionID = 241,
                CS_Division = division
            };

            CS_Employee employee = new CS_Employee()
            {
                ID = 1,
                Active = true,
                Name = "Dcecilia",
                FirstName = "Test",
                DivisionID = 241
            };

            CS_Reserve reserve = new CS_Reserve()
            {
                Active = true,
                JobID = 243,
                Type = 2,
                CS_Employee = employee,
                DivisionID = 241
            };

            EntityCollection<CS_JobDivision> JobDivision = new EntityCollection<CS_JobDivision>();

            JobDivision.Add(jobdivision);

            CS_ScopeOfWork csScopeOfWork = new CS_ScopeOfWork()
            {
                Active = true,
                ScopeOfWork = "xxcxcxc",
                JobId = 243
            };

            EntityCollection<CS_Reserve> csReserves = new EntityCollection<CS_Reserve>();
            csReserves.Add(reserve);

            EntityCollection<CS_ScopeOfWork> scopeOfWorks = new EntityCollection<CS_ScopeOfWork>();
            scopeOfWorks.Add(csScopeOfWork);

            //Arrange
            FakeObjectSet<CS_Job> fakeJobObject = new FakeObjectSet<CS_Job>();
            fakeJobObject.AddObject
                (
                    new CS_Job()
                    {
                        ID = 243,
                        Active = true,
                        CreatedBy = "rbrandao",
                        CreationDate = DateTime.Now,
                        ModificationDate = DateTime.Now,
                        ModifiedBy = "Load",
                        //Internal_Tracking = "000000025INT",
                        Number = "000243",
                        CS_ScopeOfWork = scopeOfWorks,
                        CS_JobDivision = JobDivision,
                        CS_Reserve = csReserves,
                        CS_CustomerInfo = new CS_CustomerInfo()
                        {
                            Active = true,
                            CS_Customer = new CS_Customer()
                            {
                                Active = true,
                                Name = "American Test"
                            },
                            CS_Division = division,
                            CS_Contact1 = new CS_Contact()
                            {
                                ID = 1,
                                Active = true,
                                Name = "danilo",
                                LastName = "cecilia",
                            },
                            CS_Contact3 = new CS_Contact()
                                             {
                                                 ID = 1,
                                                 Active = true,
                                                 Name = "danilo",
                                                 LastName = "cecilia",
                                             },
                            //IsCustomer = true,
                            InitialCustomerContactId = 1,
                            BillToContactId = 1

                        },
                        CS_JobInfo = new CS_JobInfo()
                        {
                            Active = true,
                            InterimBill = true,
                            CS_Employee = employee,
                            EmployeeID = employee.ID,
                            CS_Frequency = frequency,
                            FrequencyID = 1,
                            CS_JobAction = new CS_JobAction()
                            {
                                Active = true,
                                Description = "Environmental Work, General - Undefined Scope of Work"
                            },
                            CS_JobType = new CS_JobType()
                            {
                                Active = true,
                                Description = "A"
                            },
                            InitialCallDate = dt,
                            InitialCallTime = timeSpan,
                            CS_PriceType = new CS_PriceType()
                                               {
                                                   Active = true,
                                                   Acronym = "P",
                                                   Description = "description test"
                                               },
                            CS_JobCategory = new CS_JobCategory()
                                                {
                                                    Active = true,
                                                    Description = "B"
                                                },
                            CS_Job_JobStatus = new EntityCollection<CS_Job_JobStatus>()
                            {
                                new CS_Job_JobStatus()
                                {
                                    Active = true,
                                    JobStatusId = (int)Globals.JobRecord.JobStatus.Active,
                                    JobStartDate = new DateTime(2011,02,14),
                                    JobCloseDate = new DateTime(2011,02,14)
                                }
                            }

                        },
                        CS_LocationInfo = locationInfo,
                        CS_JobDescription = csJobDescription
                    }
            );

            //Act
            Mock<IUnitOfWork> mockUnitOfWork = new Mock<IUnitOfWork>();
            mockUnitOfWork.Setup(w => w.CreateObjectSet<CS_Job>()).Returns(fakeJobObject);

            JobModel jobModel = new JobModel(mockUnitOfWork.Object);

            string body = jobModel.GenerateEmailBodyForInvoicingTeam(243);

            StringBuilder sb = new StringBuilder();

            sb.Append("<div>");
            sb.Append("<div style='width: 100%; display: inline-block;'>");
            sb.Append("<div style='text-align: right;width:30%; height:100% ;display: inline-block;float:left'><b>");
            sb.Append("Job#:");
            sb.Append("</b></div>");
            sb.Append("<div style='text-align: left;width:68%; height:100% ;display: inline-block;float:right'>");
            sb.Append(" PA000243");
            sb.Append("</div>");
            sb.Append("</div>");
            sb.Append("<div style='width: 100%; display: inline-block;'>");
            sb.Append("<div style='text-align: right;width:30%; height:100% ;display: inline-block;float:left'><b>");
            sb.Append("Customer:");
            sb.Append("</b></div>");
            sb.Append("<div style='text-align: left;width:68%; height:100% ;display: inline-block;float:right'>");
            sb.Append(" American Test");
            sb.Append("</div>");
            sb.Append("</div>");
            sb.Append("<div style='width: 100%; display: inline-block;'>");
            sb.Append("<div style='text-align: right;width:30%; height:100% ;display: inline-block;float:left'><b>");
            sb.Append("Initial Customer Contact:");
            sb.Append("</b></div>");
            sb.Append("<div style='text-align: left;width:68%; height:100% ;display: inline-block;float:right'>");
            sb.Append(" danilo");
            sb.Append("</div>");
            sb.Append("</div>");
            sb.Append("<div style='width: 100%; display: inline-block;'>");
            sb.Append("<div style='text-align: right;width:30%; height:100% ;display: inline-block;float:left'><b>");
            sb.Append("Bill to:");
            sb.Append("</b></div>");
            sb.Append("<div style='text-align: left;width:68%; height:100% ;display: inline-block;float:right'>");
            sb.Append(" cecilia, danilo");
            sb.Append("</div>");
            sb.Append("</div>");
            sb.Append("<div style='width: 100%; display: inline-block;'>");
            sb.Append("<div style='text-align: right;width:30%; height:100% ;display: inline-block;float:left'><b>");
            sb.Append("Initial Call date:");
            sb.Append("</b></div>");
            sb.Append("<div style='text-align: left;width:68%; height:100% ;display: inline-block;float:right'>");
            sb.Append(" 02/14/2011");
            sb.Append("</div>");
            sb.Append("</div>");
            sb.Append("<div style='width: 100%; display: inline-block;'>");
            sb.Append("<div style='text-align: right;width:30%; height:100% ;display: inline-block;float:left'><b>");
            sb.Append("Initial Call time:");
            sb.Append("</b></div>");
            sb.Append("<div style='text-align: left;width:68%; height:100% ;display: inline-block;float:right'>");
            sb.Append(" 10:11:59");
            sb.Append("</div>");
            sb.Append("</div>");
            sb.Append("<div style='width: 100%; display: inline-block;'>");
            sb.Append("<div style='text-align: right;width:30%; height:100% ;display: inline-block;float:left'><b>");
            sb.Append("Price Type:");
            sb.Append("</b></div>");
            sb.Append("<div style='text-align: left;width:68%; height:100% ;display: inline-block;float:right'>");
            sb.Append(" description test");
            sb.Append("</div>");
            sb.Append("</div>");
            sb.Append("<div style='width: 100%; display: inline-block;'>");
            sb.Append("<div style='text-align: right;width:30%; height:100% ;display: inline-block;float:left'><b>");
            sb.Append("Job Action:");
            sb.Append("</b></div>");
            sb.Append("<div style='text-align: left;width:68%; height:100% ;display: inline-block;float:right'>");
            sb.Append(" Environmental Work, General - Undefined Scope of Work");
            sb.Append("</div>");
            sb.Append("</div>");
            sb.Append("<div style='width: 100%; display: inline-block;'>");
            sb.Append("<div style='text-align: right;width:30%; height:100% ;display: inline-block;float:left'><b>");
            sb.Append("Job Category:");
            sb.Append("</b></div>");
            sb.Append("<div style='text-align: left;width:68%; height:100% ;display: inline-block;float:right'>");
            sb.Append(" B");
            sb.Append("</div>");
            sb.Append("</div>");
            sb.Append("<div style='width: 100%; display: inline-block;'>");
            sb.Append("<div style='text-align: right;width:30%; height:100% ;display: inline-block;float:left'><b>");
            sb.Append("Job Type:");
            sb.Append("</b></div>");
            sb.Append("<div style='text-align: left;width:68%; height:100% ;display: inline-block;float:right'>");
            sb.Append(" A");
            sb.Append("</div>");
            sb.Append("</div>");
            sb.Append("<div style='width: 100%; display: inline-block;'>");
            sb.Append("<div style='text-align: right;width:30%; height:100% ;display: inline-block;float:left'><b>");
            sb.Append("Division:");
            sb.Append("</b></div>");
            sb.Append("<div style='text-align: left;width:68%; height:100% ;display: inline-block;float:right'>");
            sb.Append(" 005");
            sb.Append("</div>");
            sb.Append("</div>");
            sb.Append("<div style='width: 100%; display: inline-block;'>");
            sb.Append("<div style='text-align: right;width:30%; height:100% ;display: inline-block;float:left'><b>");
            sb.Append("Interim Bill:");
            sb.Append("</b></div>");
            sb.Append("<div style='text-align: left;width:68%; height:100% ;display: inline-block;float:right'>");
            sb.Append(" Yes");
            sb.Append("</div>");
            sb.Append("</div>");
            sb.Append("<div style='width: 100%; display: inline-block;'>");
            sb.Append("<div style='text-align: right;width:30%; height:100% ;display: inline-block;float:left'><b>");
            sb.Append("Requested By:");
            sb.Append("</b></div>");
            sb.Append("<div style='text-align: left;width:68%; height:100% ;display: inline-block;float:right'>");
            sb.Append(" Dcecilia, Test");
            sb.Append("</div>");
            sb.Append("</div>");
            sb.Append("<div style='width: 100%; display: inline-block;'>");
            sb.Append("<div style='text-align: right;width:30%; height:100% ;display: inline-block;float:left'><b>");
            sb.Append("Frequency:");
            sb.Append("</b></div>");
            sb.Append("<div style='text-align: left;width:68%; height:100% ;display: inline-block;float:right'>");
            sb.Append(" D");
            sb.Append("</div>");
            sb.Append("</div>");
            sb.Append("<div style='width: 100%; display: inline-block;'>");
            sb.Append("<div style='text-align: right;width:30%; height:100% ;display: inline-block;float:left'><b>");
            sb.Append("Country:");
            sb.Append("</b></div>");
            sb.Append("<div style='text-align: left;width:68%; height:100% ;display: inline-block;float:right'>");
            sb.Append(" USA");
            sb.Append("</div>");
            sb.Append("</div>");
            sb.Append("<div style='width: 100%; display: inline-block;'>");
            sb.Append("<div style='text-align: right;width:30%; height:100% ;display: inline-block;float:left'><b>");
            sb.Append("State:");
            sb.Append("</b></div>");
            sb.Append("<div style='text-align: left;width:68%; height:100% ;display: inline-block;float:right'>");
            sb.Append(" Texas");
            sb.Append("</div>");
            sb.Append("</div>");
            sb.Append("<div style='width: 100%; display: inline-block;'>");
            sb.Append("<div style='text-align: right;width:30%; height:100% ;display: inline-block;float:left'><b>");
            sb.Append("City:");
            sb.Append("</b></div>");
            sb.Append("<div style='text-align: left;width:68%; height:100% ;display: inline-block;float:right'>");
            sb.Append(" Dalton");
            sb.Append("</div>");
            sb.Append("</div>");
            sb.Append("<div style='width: 100%; display: inline-block;'>");
            sb.Append("<div style='text-align: right;width:30%; height:100% ;display: inline-block;float:left'><b>");
            sb.Append("Number Engines:");
            sb.Append("</b></div>");
            sb.Append("<div style='text-align: left;width:68%; height:100% ;display: inline-block;float:right'>");
            sb.Append(" 1");
            sb.Append("</div>");
            sb.Append("</div>");
            sb.Append("<div style='width: 100%; display: inline-block;'>");
            sb.Append("<div style='text-align: right;width:30%; height:100% ;display: inline-block;float:left'><b>");
            sb.Append("Number Loads:");
            sb.Append("</b></div>");
            sb.Append("<div style='text-align: left;width:68%; height:100% ;display: inline-block;float:right'>");
            sb.Append(" 2");
            sb.Append("</div>");
            sb.Append("</div>");
            sb.Append("<div style='width: 100%; display: inline-block;'>");
            sb.Append("<div style='text-align: right;width:30%; height:100% ;display: inline-block;float:left'><b>");
            sb.Append("Number Empties:");
            sb.Append("</b></div>");
            sb.Append("<div style='text-align: left;width:68%; height:100% ;display: inline-block;float:right'>");
            sb.Append(" 1");
            sb.Append("</div>");
            sb.Append("</div>");
            sb.Append("<div style='width: 100%; display: inline-block;'>");
            sb.Append("<div style='text-align: right;width:30%; height:100% ;display: inline-block;float:left'><b>");
            sb.Append("Scope Of Work:");
            sb.Append("</b></div>");
            sb.Append("<div style='text-align: left;width:68%; height:100% ;display: inline-block;float:right'>");
            sb.Append("xxcxcxc");
            sb.Append("</div>");
            sb.Append("</div>");
            sb.Append("<div style='width: 100%; display: inline-block;'>");
            sb.Append("<div style='text-align: right;width:30%; height:100% ;display: inline-block;float:left'><b>");
            sb.Append("Job start date:");
            sb.Append("</b></div>");
            sb.Append("<div style='text-align: left;width:68%; height:100% ;display: inline-block;float:right'>");
            sb.Append(" 02/14/2011 00:00:00");
            sb.Append("</div>");
            sb.Append("</div>");
            sb.Append("<div style='width: 100%; display: inline-block;'>");
            sb.Append("<div style='text-align: right;width:30%; height:100% ;display: inline-block;float:left'><b>");
            sb.Append("Job end date:");
            sb.Append("</b></div>");
            sb.Append("<div style='text-align: left;width:68%; height:100% ;display: inline-block;float:right'>");
            sb.Append(" 02/14/2011 00:00:00");
            sb.Append("</div>");
            sb.Append("</div>");
            sb.Append("</div>");

            //Assert
            Assert.AreEqual(sb.ToString(), body);
        }
        /// <summary>
        /// Saves or Updates a City
        /// </summary>
        /// <param name="city">City entity</param>
        /// <param name="zipCodeList">Zip code listing</param>
        /// <param name="username">Username</param>
        public void SaveCity(CS_City city, IList<CS_ZipCode> zipCodeList, string username)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                city.ModificationDate = DateTime.Now;
                //city.ModificationID
                city.ModifiedBy = username;
                city.CSRecord = true;
                city.Active = true;

                for (int i = 0; i < zipCodeList.Count; i++)
                {
                    zipCodeList[i].ModificationDate = DateTime.Now;
                    //zipCodeList[i].ModificationID
                    zipCodeList[i].ModifiedBy = username;
                    zipCodeList[i].Active = true;
                }

                if (city.ID == 0)
                {
                    city.CreationDate = DateTime.Now;
                    //city.CreationID
                    city.CreatedBy = username;

                    _cityRepository.Add(city);

                    for (int i = 0; i < zipCodeList.Count; i++)
                    {
                        zipCodeList[i].CityId = city.ID;
                        zipCodeList[i].CreationDate = DateTime.Now;
                        //zipCodeList[i].CreationID
                        zipCodeList[i].CreatedBy = username;
                    }

                    _zipCodeRepository.AddList(zipCodeList);
                }
                else
                {
                    _cityRepository.Update(city);

                    List<CS_ZipCode> addList = new List<CS_ZipCode>();
                    List<CS_ZipCode> updateList = new List<CS_ZipCode>();
                    List<int> currentUpdateList = zipCodeList.Where(e => e.ID != 0).Select(e => e.ID).ToList();
                    IList<CS_ZipCode> removeList = _zipCodeRepository.ListAll(e => e.Active && e.CityId == city.ID && !currentUpdateList.Contains(e.ID));

                    for (int i = 0; i < zipCodeList.Count; i++)
                    {
                        if (zipCodeList[i].ID == 0)
                        {
                            addList.Add(new CS_ZipCode()
                            {
                                CityId = city.ID,
                                Name = zipCodeList[i].Name,
                                Latitude = zipCodeList[i].Latitude,
                                Longitude = zipCodeList[i].Longitude,
                                CreatedBy = username,
                                CreationDate = DateTime.Now,
                                //CreationID
                                ModifiedBy = username,
                                ModificationDate = DateTime.Now,
                                //ModificationID
                                Active = true
                            });
                        }
                        else
                        {
                            updateList.Add(new CS_ZipCode()
                            {
                                ID = zipCodeList[i].ID,
                                CityId = city.ID,
                                Name = zipCodeList[i].Name,
                                Latitude = zipCodeList[i].Latitude,
                                Longitude = zipCodeList[i].Longitude,
                                CreatedBy = zipCodeList[i].CreatedBy,
                                CreationDate = zipCodeList[i].CreationDate,
                                //CreationID = zipCodeList[i].CreationID,
                                ModifiedBy = username,
                                ModificationDate = DateTime.Now,
                                //ModificationID
                                Active = true
                            });
                        }
                    }

                    if (addList.Count > 0) _zipCodeRepository.AddList(addList);
                    if (updateList.Count > 0) _zipCodeRepository.UpdateList(updateList);
                    if (removeList.Count > 0)
                    {
                        for (int i = 0; i < removeList.Count; i++)
                        {
                            removeList[i].ModificationDate = DateTime.Now;
                            removeList[i].ModifiedBy = username;
                            removeList[i].Active = false;
                        }

                        _zipCodeRepository.UpdateList(removeList);
                    }
                }

                scope.Complete();
            }
        }