public void TransferResources()
        {
            using (_jobModel = new JobModel())
            {
                CS_JobStatus jobStatus = _jobModel.GetJobById(_view.JobIdTo).CS_JobInfo.LastJobStatus;

                if (null == jobStatus || (null != jobStatus && jobStatus.ID != (int)Globals.JobRecord.JobStatus.Active))
                {
                    _view.DisplayMessage("Resources cannot be transfered to an inactive job.", false);
                    return;
                }
            }

            using (ResourceAllocationModel _resourceAllocationModel = new ResourceAllocationModel())
            {
                if (_view.SelectedResources.Count > 0)
                {
                    List<CS_Resource> newJobResourceSelection = CopyResourcesToNewList(_view.SelectedResources, _view.JobIdTo);
                    _resourceAllocationModel.TransferResources(_view.SelectedResources, newJobResourceSelection, _view.SelectedResourcesTransferType, _view.SelectedCallLogIds, _view.JobId, _view.JobIdTo, _view.Username);

                    _view.DisplayMessage("Resources transfered successfully!", true);
                }
                else
                {
                    _view.DisplayMessage("There was an error loading the resources for transfer, please try opening the page again.", true);
                }
            }
        }
        public void SendMail()
        {
            _jobModel = new JobModel();
            string[] receipts = _view.ReceiptsString.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

            using (_emailModel = new EmailModel())
            {

                if (_view.JobID.HasValue)
                {
                    CS_Job job = _jobModel.GetJobById(_view.JobID.Value);
                    _emailModel.SaveEmailList(string.Join(";", receipts), _view.EmailSubject, _view.EmailBody, _view.UserName, _view.CreationId);
                    _jobModel.SaveCallCriteriaInitialAdviseCallCriteriaEmailResources(_callLogModel.GetCallLogById(job.CS_CallLog.FirstOrDefault(e => e.CallTypeID == (int)Globals.CallEntry.CallType.InitialLog).ID));
                }
                else
                {
                    _emailModel.SaveEmailList(receipts, _view.ReceiptsIds, _view.EmailSubject, _view.EmailBody, _view.UserName, _view.CreationId);
                }
            }
        }
        public void JobRecordEmailFilling()
        {
            _jobModel = new JobModel();
            CS_Job job = _jobModel.GetJobById(_view.JobID.Value);

            this._jobModel = new JobModel()
                    {
                        NewJob = job,
                        NewCustomer = job.CS_CustomerInfo,
                        NewJobDivision = job.CS_JobDivision.ToList(),
                        NewPresetInfo = job.CS_PresetInfo,
                        NewLostJobInfo = job.CS_LostJobInfo,
                        NewSpecialPricing = job.CS_SpecialPricing,
                        NewJobInfo = job.CS_JobInfo,
                        NewLocationInfo = job.CS_LocationInfo,
                        NewJobDescription = job.CS_JobDescription,
                        NewScopeOfWork = job.CS_ScopeOfWork.ToList(),
                        NewPhotoReport = job.CS_JobPhotoReport.ToList(),
                        NewRequestedEquipment = _jobModel.GetEquipmentRequestedVOByJob(_view.JobID.Value),
                        JobStatusID = job.CS_JobInfo.LastJobStatus.ID,
                        NewJobStatusHistory = job.CS_JobInfo.CS_Job_JobStatus.FirstOrDefault(e => e.Active)
                    };

            string subject = _callCriteriaModel.GenerateSubjectForCallCriteria(
             job,
             job.CS_JobInfo,
             job.CS_CustomerInfo,
             job.CS_LocationInfo,
             "Initial Advise");

            IList<EmailVO> receipts = _callCriteriaModel.ListValidReceiptsByCallLog(job.CS_CallLog.FirstOrDefault(e => e.CallTypeID == (int)Globals.CallEntry.CallType.InitialLog).ID, job.ID);

            _view.EmailVOReceipts = receipts;
            _view.EmailSubject = subject;
            _view.EmailBody = _jobModel.BodyEmailJobRecordTable();
        }
 public void GetJobStatus()
 {
     try
     {
         _view.JobStatusList = new List<CS_JobStatus>();
         using (_jobModel = new JobModel())
         {
             CS_Job job = _jobModel.GetJobById(_view.JobId);
             if (job != null)
                 _view.JobStatusList.Add(job.CS_JobInfo.LastJobStatus);
         }
     }
     catch (Exception ex)
     {
         if (null != ex.InnerException)
             Logger.Write(string.Format("An error has occurred while trying to get the Job Status\n{0}\n{1}\n{2}\n{3}", ex.Message, ex.StackTrace, ex.InnerException.Message, ex.InnerException.StackTrace));
         else
             Logger.Write(string.Format("An error has occurred while trying to get the Job Status\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>
 /// Fills the Page Title with the correct information
 /// </summary>
 public void GetPageTitle()
 {
     try
     {
         if (!_view.JobId.HasValue)
             _view.PageTitle = "New Call Entry";
         else
         {
             using (_jobModel = new JobModel())
             {
                 CS_Job job = _jobModel.GetJobById(_view.JobId.Value);
                 if (null != job)
                 {
                     _view.PageTitle = string.Format("{0} - Call Entry", job.PrefixedNumber);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Logger.Write(string.Format("An Error has ocurred while trying to get the Page Title.\n{0}\n{1}", ex.Message, ex.StackTrace));
         _view.DisplayMessage("An Internal Error has ocurred while trying to load the Information. Please try again.", false);
     }
 }
 /// <summary>
 /// Updates Title information based on Job Id
 /// </summary>
 public void UpdateTitle()
 {
     try
     {
         if (_view.JobId.HasValue)
         {
             using (_model = new JobModel())
             {
                 CS_Job job = _model.GetJobById(_view.JobId.Value);
                 if (null != job && null != job.CS_JobInfo)
                 {
                     string title = string.Format("{0} - Job Record", job.PrefixedNumber);
                     _view.PageTitle = title;
                 }
             }
         }
         else
             _view.PageTitle = "New Job Record";
     }
     catch (Exception ex)
     {
         Logger.Write(string.Format("There was an error while trying to update Title information!\n{0}\n{1}", ex.Message, ex.StackTrace));
         _view.DisplayMessage("There was an error while trying to update Title information.", false);
     }
 }
        public void GetJob()
        {
            try
                {
                    if (_view.JobId.HasValue)
                    {
                        CS_CustomerInfo customerInfo = null;

                        using (_model = new JobModel())
                        {
                            _view.Job = _model.GetJobById(_view.JobId.Value);
                        }

                        using (_model = new JobModel())
                        {
                            _view.SpecialPricingEntity = _model.GetSpecialPricing(_view.JobId.Value);
                            _view.PresetInfoEntity = _model.GetPresetInfo(_view.JobId.Value);
                            _view.LostJobEntity = _model.GetLostJob(_view.JobId.Value);
                            _view.JobDivisionEntityList = _model.ListJobDivision(_view.JobId.Value);
                            _view.JobDescriptionEntity = _model.GetJobDescriptionByJobId(_view.JobId.Value);

                            if (null != _view.Job.CS_JobInfo && !string.IsNullOrEmpty(_view.Job.CS_JobInfo.CustomerSpecificInfo))
                                _view.CustomerSpecificFields = CustomerSpecificInfo.DeserializeObject(_view.Job.CS_JobInfo.CustomerSpecificInfo);

                            customerInfo = _model.GetCustomerInfoByJobId(_view.JobId.Value);
                        }

                        using (_customerModel = new CustomerModel())
                        {
                            if (null != customerInfo)
                                _view.CustomerContract = _customerModel.ListAllCustomerContracts(customerInfo.CustomerId);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Write(string.Format("An error has occurred while trying to load Job Info section!\n{0}\n{1}", ex.Message, ex.StackTrace));
                    _view.DisplayMessage("An error has occurred while trying to load Job Info Section.", false);
                }
        }