public void TestListCityByNameAndState()
 {
     // Arrange
     LocationModel model = new LocationModel(new FakeUnitOfWork());
     // Act
     IList<CS_City> result = model.ListCityByNameAndState(2, "City 1");
     // Assert
     Assert.IsNotNull(result);
     Assert.AreEqual(result.Count, 1);
 }
 public void TestListZipCodeByNameAndCity()
 {
     // Arrange
     LocationModel model = new LocationModel(new FakeUnitOfWork());
     // Act
     IList<CS_ZipCode> result = model.ListZipCodeByNameAndCity(2, "001");
     // Assert
     Assert.IsNotNull(result);
     Assert.AreEqual(result.Count, 1);
 }
        public void TestListCityByNameWithoutState()
        {
            //Arrange
            FakeObjectSet<CS_City> fakeCityList = new FakeObjectSet<CS_City>();
            fakeCityList.AddObject(new CS_City() { ID = 1, Active = true, Name = "City 1" });
            Mock<IUnitOfWork> mock = new Mock<IUnitOfWork>();
            mock.Setup(e => e.CreateObjectSet<CS_City>()).Returns(fakeCityList);
            LocationModel model = new LocationModel(mock.Object);

            //Act
            IList<CS_City> city = model.ListCityByNameAndState(0, "City 1");

            //Assert
            Assert.AreEqual(1, city.Count);
            Assert.IsNotNull(city);
        }
        public ResourceAllocationViewModel(IResourceAllocationView view)
        {
            _view = view;

            _equipmentModel = new EquipmentModel();
            _divisionModel = new DivisionModel();
            _employeeModel = new EmployeeModel();
            _resourceAllocationModel = new ResourceAllocationModel();
            _locationModel = new LocationModel();
            _jobModel = new JobModel();
            _callLogModel = new CallLogModel();

            _divisionNumber = string.Empty;
            _name = string.Empty;
            _type = Globals.ResourceAllocation.Type.AddEmployee;
        }
        public void ShouldReturnFullStateNameFromPrefix()
        {
            //Arrange
            bool result = true;
            LocationModel model = new LocationModel(new FakeUnitOfWork());

            //Act
            IList<CS_State> states = model.ListAllStatesByName("New");

            for (int i = 0; i < states.Count; i++)
            {
                if (!states[i].Name.ToLower().Contains("new"))
                {
                    result = false;
                    break;
                }
            }

            //Assert
            Assert.IsTrue(result);
        }
        public void GetStateAndCountryByCity()
        {
            try
            {
                using (_locationModel = new LocationModel())
                {
                    CS_State state = _locationModel.GetStateByCityId(_view.CityId);

                    if (null != state)
                    {
                        _view.StateAndCountryDataObject = new Globals.StateAndCountryDataObject();
                        _view.StateAndCountryDataObject.StateId = state.ID;
                        _view.StateAndCountryDataObject.StateName = state.AcronymName;
                        _view.StateAndCountryDataObject.CountryId = state.CountryID;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Write(string.Format("An Error has ocurred while trying to get ZipCode by City.\n{0}\n{1}", ex.Message, ex.StackTrace));
            }
        }
 /// <summary>
 /// List all active ZipCodes filtered by City and Name (Like)
 /// </summary>
 public void ListZipCodesByNameAndCity()
 {
     try
     {
         using (_locationModel = new LocationModel())
         {
             _view.ZipCodeList = _locationModel.ListZipCodeByNameAndCity(int.Parse(_view.ContextKey), _view.PrefixText);
         }
     }
     catch (Exception ex)
     {
         Logger.Write(string.Format("An Error has ocurred while trying to load the Zip Code Information!\n{0}\n{1}", ex.Message, ex.StackTrace));
     }
 }
 /// <summary>
 /// List all active States
 /// </summary>
 public void ListStatesByAcronymAndDivision()
 {
     try
     {
         using (_locationModel = new LocationModel())
         {
             _view.StateList = _locationModel.ListAllStatesByAcronymAndDivision(_view.PrefixText);
         }
     }
     catch (Exception ex)
     {
         Logger.Write(string.Format("An Error has ocurred while trying to load the State Information!\n{0}\n{1}", ex.Message, ex.StackTrace));
     }
 }
        public void DoStuff(object sender, EventArgs e)
        {
            if (_targetControl is DynamicDropDownList)
            {
                DynamicDropDownList control = _targetControl as DynamicDropDownList;

                if ((_filteredLoadOnly && control.FilterId != 0) || !_filteredLoadOnly)
                {
                    switch (_type)
                    {
                        case Globals.CallEntry.ListType.Custom:
                            control = _targetControl as DynamicDropDownList;

                            control.DataTextField = "Name";
                            control.DataValueField = "Value";

                            control.DataSource = _items;
                            control.DataBind();

                            if (string.IsNullOrEmpty(control.SelectedValue))
                            {
                                ListExtenderItem item = _items.Find(delegate(ListExtenderItem match) { return match.Selected; });
                                control.Items.FindByValue(item.Value).Selected = true;
                            }

                            break;
                        case Globals.CallEntry.ListType.Country:

                            IList<CS_Country> countryList = null;
                            using (LocationModel model = new LocationModel())
                            {
                                countryList = model.ListAllCountries();
                            }

                            control.SelectedIndex = -1;
                            control.DataTextField = "Name";
                            control.DataValueField = "ID";
                            control.DataSource = countryList;
                            control.DataBind();
                            control.Items.Insert(0, new ListItem("- Select One -", ""));

                            break;
                        case Globals.CallEntry.ListType.State:

                            control = _targetControl as DynamicDropDownList;
                            IList<CS_State> stateList = null;
                            using (LocationModel model = new LocationModel())
                            {
                                if (control.FilterId > 0)
                                    stateList = model.GetStateByCountryId(control.FilterId);
                                else
                                    stateList = model.ListAllStatesOrderedByCountry();
                            }

                            control.SelectedIndex = -1;
                            control.DataTextField = "Name";
                            control.DataValueField = "ID";
                            control.DataSource = stateList;
                            control.DataBind();
                            control.Items.Insert(0, new ListItem("- Select One -", ""));

                            break;
                        case Globals.CallEntry.ListType.City:

                            control = _targetControl as DynamicDropDownList;
                            IList<CS_City> cityList = null;
                            using (LocationModel model = new LocationModel())
                            {
                                if (control.FilterId > 0)
                                    cityList = model.GetCityByState(control.FilterId);
                                else
                                    cityList = model.ListAllCities();
                            }

                            control.DataTextField = "Name";
                            control.DataValueField = "ID";
                            control.DataSource = cityList;
                            control.DataBind();
                            control.Items.Insert(0, new ListItem("- Select One -", ""));

                            break;
                        case Globals.CallEntry.ListType.Hotel:

                            control = _targetControl as DynamicDropDownList;
                            IList<CS_Hotel> hotelList = null;
                            using (CallLogModel model = new CallLogModel())
                            {
                                hotelList = model.ListAllHotels();
                            }

                            control.DataTextField = "Description";
                            control.DataValueField = "ID";
                            control.DataSource = hotelList;
                            control.DataBind();
                            control.Items.Insert(0, new ListItem("- Select One -", ""));

                            break;
                        case Globals.CallEntry.ListType.Subcontractor:

                            control = _targetControl as DynamicDropDownList;
                            IList<CS_Subcontractor> subcontractorList = null;
                            using (CallLogModel model = new CallLogModel())
                            {
                                subcontractorList = model.ListAllSubcontractors();
                            }

                            control.DataTextField = "Name";
                            control.DataValueField = "ID";
                            control.DataSource = subcontractorList;
                            control.DataBind();
                            control.Items.Insert(0, new ListItem("- Select One -", ""));

                            break;
                    }
                }
            }
            else if (_targetControl is DynamicRadioButtonList)
            {
                DynamicRadioButtonList control = _targetControl as DynamicRadioButtonList;

                if (!_filteredLoadOnly)
                {
                    switch (_type)
                    {
                        case Globals.CallEntry.ListType.Custom:
                            control = _targetControl as DynamicRadioButtonList;

                            control.DataTextField = "Name";
                            control.DataValueField = "Value";

                            control.DataSource = _items;
                            control.DataBind();

                            ListExtenderItem item = _items.Find(delegate(ListExtenderItem match) { return match.Selected; });
                            if (item != null)
                                control.Items.FindByValue(item.Value).Selected = true;

                            break;
                    }
                }
            }
        }
 /// <summary>
 /// List All Countries in the Database
 /// </summary>
 public void ListAllCountries()
 {
     try
     {
         using (_locationModel = new LocationModel())
         {
             _view.CountryList = _locationModel.ListAllCountries();
         }
     }
     catch (Exception ex)
     {
         Logger.Write(string.Format("An Error has ocurred while trying to load the country list list.\n{0}\n{1}", ex.Message, ex.StackTrace));
         _view.DisplayMessage("An Internal Error has ocurred while trying to load the country list.", false);
     }
 }
 public CityMaintenanceViewModel(ICityMaintenanceView view, LocationModel model)
 {
     _view = view;
     _model = model;
 }
        public void GetFirstZipCodeByCity()
        {
            try
            {
                using (_locationModel = new LocationModel())
                {
                    CS_ZipCode zipCode = _locationModel.GetZipCodeByCityId(_view.CityId).FirstOrDefault();

                    if (null != zipCode)
                    {
                        _view.ReturnDataObject = new Globals.SampleDataObject();
                        _view.ReturnDataObject.Id = zipCode.ID;
                        _view.ReturnDataObject.Name = zipCode.ZipCodeNameEdited;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Write(string.Format("An Error has ocurred while trying to get ZipCode by City.\n{0}\n{1}", ex.Message, ex.StackTrace));
            }
        }
        private void BindList()
        {
            CustomerModel customerModel;
            EmployeeModel employeeModel;
            LocationModel locationModel;
            DivisionModel divisionModel;
            JobModel jobModel;
            CallLogModel callLogModel;
            EquipmentModel equipmentModel;

            IList<CS_Customer> customerDataSource;
            IList<CS_Contact> contactDataSource;
            IList<CS_Employee> employeeDataSource;
            IList<CS_JobStatus> jobStatusDataSource;
            IList<CS_City> cityDataSource;
            IList<CS_Division> divisionDataSource;
            IList<CS_PriceType> priceTypeDataSource;
            IList<CS_JobAction> jobActionDataSource;
            IList<CS_Job> jobNumberDataSource;
            IList<CS_ZipCode> zipCodeDataSource;
            IList<CS_State> stateDataSource;
            IList<CS_CallType> callTypeDataSource;
            IList<CS_EquipmentType> equipmentTypeDataSource;
            IList<CS_Equipment> equipmentDataSource;
            IList<CS_LocalEquipmentType> localEquipmentTypeDataSource;

            switch (Request.QueryString["AutoCompleteSource"])
            {
                case "Customer":
                    customerModel = new CustomerModel();
                    customerDataSource = customerModel.ListAllCustomers().OrderBy(e => e.Name).ToList();
                    ViewStateList = customerDataSource;

                    break;

                case "Contact":
                    customerModel = new CustomerModel();
                    contactDataSource = customerModel.ListAllFilteredContactsByName(long.Parse(Request.QueryString["FilterId"]), "").OrderBy(e => e.LastName).ThenBy(e => e.Name).ToList();
                    ViewStateList = contactDataSource;

                    break;

                case "DynamicsContact":
                    customerModel = new CustomerModel();
                    contactDataSource = customerModel.ListFilteredContactsByName(long.Parse(Request.QueryString["FilterId"]), true, "").OrderBy(e => e.Attn).ToList();
                    ViewStateList = contactDataSource;

                    break;

                case "CustomerServiceContact":
                    customerModel = new CustomerModel();
                    contactDataSource = customerModel.ListFilteredContactsByName(long.Parse(Request.QueryString["FilterId"]), false, "").OrderBy(e => e.LastName).ThenBy(e => e.Name).ToList();
                    ViewStateList = contactDataSource;

                    break;

                case "Employee":
                    employeeModel = new EmployeeModel();

                    if (Request.QueryString["FilterId"] != "0")
                        employeeDataSource = employeeModel.ListAllFilteredEmployee(long.Parse(Request.QueryString["FilterId"])).OrderBy(e => e.CS_Division.Name).ThenBy(e => e.FullName).ToList();
                    else
                        employeeDataSource = employeeModel.ListAllEmployee().OrderBy(e => e.CS_Division.Name).ThenBy(e => e.FullName).ToList();
                    ViewStateList = employeeDataSource;

                    break;
                case "EmployeeWithDivision":
                    employeeModel = new EmployeeModel();

                    if (Request.QueryString["FilterId"] != "0")
                        employeeDataSource = employeeModel.ListAllFilteredEmployee(long.Parse(Request.QueryString["FilterId"])).OrderBy(e => e.CS_Division.Name).ThenBy(e => e.FullName).ToList();
                    else
                        employeeDataSource = employeeModel.ListAllEmployee().OrderBy(e => e.CS_Division, new Globals.JobRecord.EmployeeComparer()).ThenBy(e => e.FullName).ToList();
                    ViewStateList = employeeDataSource;
                    break;

                case "JobStatus":
                    jobModel = new JobModel();

                    if (!string.IsNullOrEmpty(Request.QueryString.Get("FilterId")) && Request.QueryString["FilterId"] != "0")
                    {
                        jobStatusDataSource = new List<CS_JobStatus>();
                        jobStatusDataSource.Add(jobModel.GetJobStatus(int.Parse(Request.QueryString["FilterId"])));
                    }
                    else
                        jobStatusDataSource = jobModel.ListAllJobStatus();
                    ViewStateList = jobStatusDataSource;
                    break;
                case "JobStatusJobRecord":
                    jobModel = new JobModel();

                    if (!string.IsNullOrEmpty(Request.QueryString.Get("FilterId")) && Request.QueryString["FilterId"] != "0" && Request.QueryString["FilterId"] != Globals.JobRecord.JobStatus.ClosedHold.ToString())
                    {
                        jobStatusDataSource = new List<CS_JobStatus>();
                        jobStatusDataSource.Add(jobModel.GetJobStatus(int.Parse(Request.QueryString["FilterId"])));
                    }
                    else
                    {
                        jobStatusDataSource = jobModel.ListAllJobStatus();

                        if (jobStatusDataSource.Count > 0)
                        {
                            CS_JobStatus jobStatus = jobStatusDataSource.Where(w => w.ID == (int)Globals.JobRecord.JobStatus.ClosedHold).FirstOrDefault();
                            if (null != jobStatus)
                                jobStatusDataSource.Remove(jobStatus);
                        }
                    }
                    ViewStateList = jobStatusDataSource;
                    break;
                case "State":
                    locationModel = new LocationModel();
                    if (!string.IsNullOrEmpty(Request.QueryString.Get("FilterId")) && Request.QueryString.Get("FilterId") != "0")
                        stateDataSource = locationModel.GetStateByCountryId(int.Parse(Request.QueryString.Get("FilterId")));
                    else
                        stateDataSource = locationModel.ListAllStates();
                    ViewStateList = stateDataSource;
                    break;
                case "StateByDivision":
                    locationModel = new LocationModel();
                    stateDataSource = locationModel.ListAllStatesByAllocatedDivision();

                    ViewStateList = stateDataSource;
                    break;
                case "City":
                    locationModel = new LocationModel();

                    if (!string.IsNullOrEmpty(Request.QueryString.Get("FilterId")) && Request.QueryString.Get("FilterId") != "0")
                        cityDataSource = locationModel.GetCityByState(int.Parse(Request.QueryString.Get("FilterId"))).OrderBy(e => e.Name).ToList();
                    else
                        cityDataSource = locationModel.ListAllCities().OrderBy(e => e.Name).ToList();
                    ViewStateList = cityDataSource;
                    break;

                case "Division":
                    divisionModel = new DivisionModel();
                    divisionDataSource = divisionModel.ListAllDivision();
                    ViewStateList = divisionDataSource;
                    break;
                case "PriceType":
                    jobModel = new JobModel();
                    priceTypeDataSource = jobModel.ListAllPriceTypes();
                    ViewStateList = priceTypeDataSource;
                    break;

                case "JobAction":
                    jobModel = new JobModel();
                    jobActionDataSource = jobModel.ListAllJobActions().OrderBy(w => w.Description).ToList();
                    ViewStateList = jobActionDataSource;
                    break;
                case "ZipCode":
                    locationModel = new LocationModel();
                    if (!string.IsNullOrEmpty(Request.QueryString.Get("FilterId")) && Request.QueryString.Get("FilterId") != "0")
                        zipCodeDataSource = locationModel.GetZipCodeByCityId(int.Parse(Request.QueryString.Get("FilterId"))).OrderBy(e => e.ZipCodeNameEdited).ToList();
                    else
                        zipCodeDataSource = locationModel.ListAllZipCodes();
                    ViewStateList = zipCodeDataSource;
                    break;
                case "JobNumber":
                    jobModel = new JobModel();

                    if (!string.IsNullOrEmpty(Request.QueryString.Get("FilterId")) && Request.QueryString["FilterId"] != "0")
                    {
                        jobNumberDataSource = new List<CS_Job>();
                        jobNumberDataSource.Add(jobModel.GetJobById(int.Parse(Request.QueryString["FilterId"])));
                    }
                    else
                        jobNumberDataSource = jobModel.ListAllJobs();

                    ViewStateList = jobNumberDataSource;
                    break;
                case "JobNumberByStatus":
                    jobModel = new JobModel();

                    if (!string.IsNullOrEmpty(Request.QueryString.Get("FilterId")) && Request.QueryString["FilterId"] != "0")
                    {
                        jobNumberDataSource = new List<CS_Job>();
                        jobNumberDataSource = jobModel.ListAllJobsByNumber("", Request.QueryString["FilterId"]);
                    }
                    else
                        jobNumberDataSource = jobModel.ListAllJobs();

                    ViewStateList = jobNumberDataSource;
                    break;
                case "JobNumberWithGeneral":
                    jobModel = new JobModel();

                    if (!string.IsNullOrEmpty(Request.QueryString.Get("FilterId")) && Request.QueryString["FilterId"] != "0")
                    {
                        jobNumberDataSource = new List<CS_Job>();
                        jobNumberDataSource.Add(jobModel.GetJobById(int.Parse(Request.QueryString["FilterId"])));
                    }
                    else
                    {
                        List<CS_Job> source = new List<CS_Job>();

                        source.Add(jobModel.GetGeneralJob());
                        source.AddRange(jobModel.ListAllJobs());

                        jobNumberDataSource = source;
                    }

                    ViewStateList = jobNumberDataSource;
                    break;
                case "BillableJobNumber":
                    jobModel = new JobModel();

                    if (!string.IsNullOrEmpty(Request.QueryString.Get("FilterId")) && Request.QueryString["FilterId"] != "0")
                    {
                        jobNumberDataSource = new List<CS_Job>();
                        jobNumberDataSource.Add(jobModel.GetJobById(int.Parse(Request.QueryString["FilterId"])));
                    }
                    else
                        jobNumberDataSource = jobModel.ListAllBillableJobs();

                    ViewStateList = jobNumberDataSource;
                    break;
                case "CallType":
                    callLogModel = new CallLogModel();

                    if (!string.IsNullOrEmpty(Request.QueryString.Get("FilterId")) && Request.QueryString["FilterId"] != "0")
                    {
                        callTypeDataSource = new List<CS_CallType>();
                        callTypeDataSource.Add(callLogModel.GetCallType(int.Parse(Request.QueryString["FilterId"])));
                    }
                    else
                        callTypeDataSource = callLogModel.ListAllCallType();

                    ViewStateList = callTypeDataSource;
                    break;
                case "EquipmentType":
                    equipmentModel = new EquipmentModel();

                    if (!string.IsNullOrEmpty(Request.QueryString.Get("FilterId")) && Request.QueryString["FilterId"] != "0")
                    {
                        equipmentTypeDataSource = new List<CS_EquipmentType>();
                        equipmentTypeDataSource.Add(equipmentModel.GetEquipmentType(int.Parse(Request.QueryString["FilterId"])));
                    }
                    else
                        equipmentTypeDataSource = equipmentModel.ListAllEquipmentType();

                    ViewStateList = equipmentTypeDataSource;
                    break;
                case "Equipment":
                    equipmentModel = new EquipmentModel();

                    if (!string.IsNullOrEmpty(Request.QueryString.Get("FilterId")) && Request.QueryString["FilterId"] != "0")
                    {
                        equipmentDataSource = new List<CS_Equipment>();
                        equipmentDataSource = equipmentModel.GetEquipmentByEqType(int.Parse(Request.QueryString["FilterId"])).OrderBy(w => w.Name).ToList();
                    }
                    else
                        equipmentDataSource = equipmentModel.ListAllEquipment().OrderBy(w => w.Name).ToList(); ;

                    ViewStateList = equipmentDataSource;
                    break;
                case "LocalEquipmentType":
                    equipmentModel = new EquipmentModel();

                    if (!string.IsNullOrEmpty(Request.QueryString.Get("FilterId")) && Request.QueryString["FilterId"] != "0")
                    {
                        localEquipmentTypeDataSource = new List<CS_LocalEquipmentType>();
                        localEquipmentTypeDataSource.Add(equipmentModel.GetLocalEquipmentTypeByID(int.Parse(Request.QueryString["FilterId"])));
                    }
                    else
                        localEquipmentTypeDataSource = equipmentModel.ListAllLocalEquipmentType();

                    ViewStateList = localEquipmentTypeDataSource;
                    break;
                case "ProjectManager":
                    employeeModel = new EmployeeModel();

                    employeeDataSource = employeeModel.ListAllEmployeeProjectManager();

                    ViewStateList = employeeDataSource;

                    break;
                default:
                    break;
            }
        }
        /// <summary>
        /// Generates the subject for the Transportation team
        /// </summary>
        /// <param name="license"></param>
        /// <param name="states"></param>
        /// <returns></returns>
        public string GenerateEmailSubjectTransportationTeam(CS_EquipmentPermit license)
        {
            CS_State state = new CS_State();
            using (_locationModel = new LocationModel())
            {
                state = _locationModel.ListAllStatesByAcronym(license.Code).FirstOrDefault();
            }

            if (null != license)
                return string.Format("Expired permit(s) identified for {0}, from {1}, in {2}, for {3}", license.LicenseNumber, license.CS_Equipment.DivisionName, ((null != state) ? state.AcronymName : string.Empty), license.Type);

            return string.Empty;
        }
        /// <summary>
        /// Dispose all objects that are no longer needed
        /// </summary>
        public void Dispose()
        {
            _equipmentInfoRepository = null;
            _equipmentRepository = null;
            _equipmentTypeRepository = null;
            _viewReserveEquipmentRepository = null;
            _conflictedCombosRepository = null;
            _equipmentPermitEmailRepository = null;
            _resourceRepository = null;

            if (null != _settingsModel)
            {
                _settingsModel.Dispose();
                _settingsModel = null;
            }

            if (null != _locationModel)
            {
                _locationModel.Dispose();
                _locationModel = null;
            }

            if (null != _emailModel)
            {
                _emailModel.Dispose();
                _emailModel = null;
            }

            if (null != _callLogModel)
            {
                _callLogModel.Dispose();
                _callLogModel = null;
            }

            _unitOfWork.Dispose();
            _unitOfWork = null;
        }
        /// <summary>
        /// Generates body for the email for the Transportation team
        /// </summary>
        /// <param name="license"></param>
        /// <param name="expiredPermits"></param>
        /// <param name="states"></param>
        /// <returns></returns>
        private string GenerateEmailBodyForTransportationTeam(CS_EquipmentPermit permit)
        {
            StringBuilder _permitEmail = new StringBuilder();

            CS_State state = new CS_State();
            using (_locationModel = new LocationModel())
            {
                state = _locationModel.ListAllStatesByAcronym(permit.Code).FirstOrDefault();
            }

            _permitEmail.AppendFormat("{0} was issued a permit on {1} which expired on {2} in {3} for the {4} permit. Please update the permit information in Dossier.", permit.CS_Equipment.Name, permit.IssueDate.ToString("MM/dd/yyyy HH:mm"), permit.ExpirationDate.ToString("MM/dd/yyyy HH:mm"), ((null != state) ? state.AcronymName : string.Empty), permit.Type);

            return StringManipulation.TabulateString(_permitEmail.ToString());
        }
        /// <summary>
        /// Sends the email notification for the permit team
        /// </summary>
        /// <param name="equipmentPermitId">job id</param>
        public IList<CS_EquipmentPermitEmail> SendNotificationForPermitTeam(IList<CS_EquipmentPermit> expiredPermits)
        {
            _settingsModel = new SettingsModel();

            try
            {
                IList<CS_EquipmentPermit> expiredLicenses = expiredPermits.Distinct(new Globals.EmailService.CS_EquipmentPermit_Comparer()).ToList();

                IList<CS_State> states = new List<CS_State>();
                using (_locationModel = new LocationModel())
                {
                    states = _locationModel.ListAllStates();
                }

                IList<CS_EquipmentPermitEmail> returnList = new List<CS_EquipmentPermitEmail>();

                for (int i = 0; i < expiredLicenses.Count; i++)
                {
                    CS_EquipmentPermit license = expiredLicenses[i];
                    IList<CS_EquipmentPermit> expiredEquipments = expiredPermits.Where(e => e.LicenseNumber == license.LicenseNumber && e.Code == license.Code).ToList();
                    IList<CS_Email> emails = new List<CS_Email>();

                    //Body
                    string body = GenerateEmailBodyForPermitTeam(license, expiredEquipments, states);

                    //List receipts
                    string receipts = _settingsModel.GetPermitTeamEmails();

                    //Subject
                    string subject = GenerateEmailSubjectEstimationTeam(license, states);

                    if (!string.IsNullOrEmpty(receipts))
                    {
                        using (_emailModel = new EmailModel())
                        {
                            emails = _emailModel.SaveEmailList(receipts, subject, body, "System", Globals.Security.SystemEmployeeID);
                        }
                    }

                    for (int j = 0; j < expiredEquipments.Count; j++)
                    {
                        CS_EquipmentPermit equipmentPermit = expiredEquipments[j];
                        for (int h = 0; h < emails.Count; h++)
                        {
                            CS_Email email = emails[h];
                            returnList.Add
                                (
                                    new CS_EquipmentPermitEmail()
                                    {
                                        EmailID = email.ID,
                                        EquipmentPermitID = equipmentPermit.Id,
                                        CreatedBy = "System",
                                        CreationDate = email.CreationDate,
                                        CreationID = Globals.Security.SystemEmployeeID,
                                        ModifiedBy = "System",
                                        ModificationDate = email.CreationDate,
                                        ModificationID = Globals.Security.SystemEmployeeID,
                                        Active = true
                                    }
                                );
                        }
                    }
                }

                return returnList;
            }
            catch (Exception ex)
            {
                throw new Exception("There was an error sending the email notification for the Permit Team.", ex);
            }
        }
 public void ListCityByNameAndState()
 {
     try
     {
         using (_locationModel = new LocationModel())
         {
             _view.CityList = _locationModel.ListCityByNameAndState(int.Parse(_view.FilterValue), _view.FilterText);
         }
     }
     catch (Exception ex)
     {
         Logger.Write(string.Format("An Error has ocurred while trying to load the City Information!\n{0}\n{1}", ex.Message, ex.StackTrace));
     }
 }
 public LocationInfoPresenter(ILocationInfoView view)
 {
     this._view = view;
     this._model = new LocationModel();
     this._jobModel = new JobModel();
 }
 public CityMaintenancePresenter(ICityMaintenanceView view)
 {
     _view = view;
     _model = new LocationModel();
     _viewModel = new CityMaintenanceViewModel(_view, _model);
 }
 /// <summary>
 /// Class Constructor
 /// </summary>
 /// <param name="view">Instance of the Essential Job Data View Interface</param>
 public EssentialJobDataViewModel(IEssentialJobDataView view)
 {
     _view = view;
     _jobModel = new JobModel();
     _locationModel = new LocationModel();
 }
        public void ListStates()
        {
            try
            {
                if (_view.FilterList.Count > 0)
                {
                    using (_locationModel = new LocationModel())
                    {
                        _view.StateList = _locationModel.ListStatesByIds(_view.FilterList);
                    }
                }
                else
                    _view.StateList = new List<CS_State>();

            }
            catch (Exception ex)
            {
                Logger.Write(string.Format("An Error has ocurred while trying to load the state list.\n{0}\n{1}", ex.Message, ex.StackTrace));
                _view.DisplayMessage("An Internal Error has ocurred while trying to load the state list.", false);
            }
        }
 /// <summary>
 /// Class Constructor
 /// </summary>
 /// <param name="view"></param>
 public RouteMaintenanceViewModel(IRouteMaintenanceView view)
 {
     _view = view;
     _divisionModel = new DivisionModel();
     _locationModel = new LocationModel();
 }