/// <summary>
        /// Generates records for a FirstAlert Call Criteria Resources
        /// </summary>
        /// <param name="initialAdvise">Generated Initial Advise Call Log</param>
        private IList<EmailVO> SaveCallCriteriaFirstAlertResources(CS_CallLog firstAlert)
        {
            try
            {
                IList<CS_CallLogResource> saveList = new List<CS_CallLogResource>();
                IList<CS_CallLogCallCriteriaEmail> emailSaveList = new List<CS_CallLogCallCriteriaEmail>();

                IList<EmailVO> resourceList = _callCriteriaModel.ListReceiptsByCallLog(firstAlert.CallTypeID.ToString(), firstAlert.JobID, firstAlert);

                for (int i = 0; i < resourceList.Count; i++)
                {
                    // Because of the Type, we need to separate the PersonID in two different variables
                    int? employeeId = null;
                    int? contactId = null;
                    if (resourceList[i].Type == (int)Globals.CallCriteria.EmailVOType.Employee)
                        employeeId = resourceList[i].PersonID;
                    else
                        contactId = resourceList[i].PersonID;

                    CS_CallLogResource resource = new CS_CallLogResource()
                    {
                        CallLogID = firstAlert.ID,
                        EmployeeID = employeeId,
                        ContactID = contactId,
                        JobID = firstAlert.JobID,
                        Type = resourceList[i].Type,
                        CreatedBy = firstAlert.CreatedBy,
                        CreationDate = DateTime.Now,
                        ModifiedBy = firstAlert.ModifiedBy,
                        ModificationDate = DateTime.Now,
                        Active = true
                    };

                    saveList.Add(resource);

                    CS_CallLogCallCriteriaEmail emailResource = new CS_CallLogCallCriteriaEmail()
                    {
                        CallLogID = firstAlert.ID,
                        Name = resourceList[i].Name,
                        Email = resourceList[i].Email,
                        Status = (int)Globals.CallCriteria.CallCriteriaEmailStatus.Pending,
                        StatusDate = DateTime.Now,
                        //CreationID = ,
                        CreatedBy = firstAlert.CreatedBy,
                        CreationDate = DateTime.Now,
                        //ModificationID,
                        ModifiedBy = firstAlert.ModifiedBy,
                        ModificationDate = DateTime.Now,
                        Active = true
                    };

                    emailSaveList.Add(emailResource);
                }

                _callLogResourceRepository.AddList(saveList);

                _callLogCallCriteriaEmailRepository.AddList(emailSaveList);

                return resourceList;
            }
            catch (Exception ex)
            {
                throw new Exception("There was an error while trying to save the First Alert Resources.", ex);
            }
        }
        private string GenerateEmailSubjectForWhiteLight(CS_CallLog callLog, CS_CallLogResource resource)
        {
            StringBuilder subject = new StringBuilder();
            int jobID = callLog.JobID;
            CS_Job job = _jobRepository.Get(e => e.ID == jobID, "CS_CustomerInfo", "CS_CustomerInfo.CS_Customer", "CS_JobInfo", "CS_JobInfo.CS_JobAction", "CS_LocationInfo", "CS_LocationInfo.CS_City", "CS_LocationInfo.CS_State");

            subject.Append(job.PrefixedNumber);
            subject.Append(", ");

            if (callLog.CS_Job.ID != (int)Globals.GeneralLog.ID)
            {
                subject.Append(job.CS_CustomerInfo.CS_Customer.Name.Trim());
                subject.Append(", ");
                subject.Append(job.CS_JobInfo.CS_JobAction.Description);
                subject.Append(", ");
                subject.Append(job.CS_LocationInfo.CS_City.Name);
                subject.Append(" ");
                subject.Append(job.CS_LocationInfo.CS_State.Acronym);
            }

            else
            {
                subject.Append(resource.CS_Equipment.CS_Division.Name);
                subject.Append(", ");
                subject.Append(resource.CS_Equipment.CS_Division.CS_State.Name);

            }

            subject.Append(", White Light");

            return subject.ToString();
        }
 private IList<CS_CallLogResource> CreateDeleteCallLogResourceEntity()
 {
     IList<CS_CallLogResource> callLogListToRemove = new List<CS_CallLogResource>();
     IList<CS_CallLogResource> oldCallLogResourceList = _callLogModel.ListCallLogResourcesByCallLog(_view.CallLogIdToDelete);
     for (int i = 0; i < oldCallLogResourceList.Count; i++)
     {
         CS_CallLogResource callLogResource = new CS_CallLogResource();
         callLogResource.ID = oldCallLogResourceList[i].ID;
         callLogResource.CallLogID = oldCallLogResourceList[i].CallLogID;
         callLogResource.EmployeeID = oldCallLogResourceList[i].EmployeeID;
         callLogResource.EquipmentID = oldCallLogResourceList[i].EquipmentID;
         callLogResource.ContactID = oldCallLogResourceList[i].ContactID;
         callLogResource.JobID = oldCallLogResourceList[i].JobID;
         callLogResource.Type = oldCallLogResourceList[i].Type;
         callLogResource.CreatedBy = oldCallLogResourceList[i].CreatedBy;
         callLogResource.CreationDate = oldCallLogResourceList[i].CreationDate;
         callLogResource.ModifiedBy = _view.UserName;
         callLogResource.ModificationDate = DateTime.Now;
         callLogResource.Active = false;
         callLogResource.InPerson = oldCallLogResourceList[i].InPerson;
         callLogResource.Voicemail = oldCallLogResourceList[i].Voicemail;
         callLogListToRemove.Add(callLogResource);
     }
     return callLogListToRemove;
 }
        private string GenerateEmailBodyForWhiteLight(CS_CallLogResource resources)
        {
            StringBuilder body = new StringBuilder();

            body.Append("<div>");

            body.Append("<div style='width: 100%; display: inline-block;'>");
            body.Append("<div style='text-align: right; width: 30%; height: 100%; display: inline-block; float: left'>");
            body.Append("<b>Call Log Details</b>");
            body.Append("</div><div style='text-align: left; width: 68%; height: 100%; display: inline-block; float: right'></div>");
            body.Append("</div>");

            string description = resources.CS_Equipment.Name;
            string date = resources.CS_Equipment.CS_EquipmentWhiteLight.FirstOrDefault(w => w.Active).WhiteLightStartDate.ToString("MM/dd/yyyy");

            //Description
            body.Append("<div style='width: 100%; display: inline-block;'>");
            body.Append("<div style='text-align: right; width: 30%; height: 100%; display: inline-block; float: left'>");
            body.Append("<b>White Light: </b>");
            body.Append("</div><div style='text-align: left; width: 68%; height: 100%; display: inline-block; float: right'>");
            body.Append(description);
            body.Append("</div>");
            body.Append("</div>");

            //Date
            body.Append("<div style='width: 100%; display: inline-block;'>");
            body.Append("<div style='text-align: right; width: 30%; height: 100%; display: inline-block; float: left'>");
            body.Append("<b>Start Date: </b>");
            body.Append("</div><div style='text-align: left; width: 68%; height: 100%; display: inline-block; float: right'>");
            body.Append(date);
            body.Append("</div>");
            body.Append("</div>");
            body.Append("</div>");

            return body.ToString();
        }
        public void SendNotificationWhiteLight(CS_CallLog callentry, CS_CallLogResource resource)
        {
            _emailModel = new EmailModel();

            IList<CS_Email> emails = new List<CS_Email>();
            string receipts = string.Empty;

            //List receipts
            IList<EmailVO> receiptsEmail = _callCriteriaModel.ListReceiptsByCallLog(callentry.CallTypeID.ToString(), callentry.JobID, callentry);

            if (receiptsEmail.Count > 0)
            {
                for (int i = 0; i < receiptsEmail.Count; i++)
                    receipts += (i == 0) ? receiptsEmail[i].Email : string.Format(";{0}", receiptsEmail[i].Email);

                //Body
                string body = GenerateEmailBodyForWhiteLight(resource);

                //Subject
                string subject = GenerateEmailSubjectForWhiteLight(callentry, resource);

                emails = _emailModel.SaveEmailList(receipts, subject, body, "System", Globals.Security.SystemEmployeeID);

                _callCriteriaModel.SendCallLogCriteriaEmails(callentry);
            }
        }
        public void SaveWhiteLightCallLogResources(CS_CallLog newCallLog, CS_EquipmentWhiteLight equipmentWhiteLight)
        {
            try
            {
                IList<CS_CallLogResource> saveList = new List<CS_CallLogResource>();
                IList<CS_CallLogCallCriteriaEmail> emailSaveList = new List<CS_CallLogCallCriteriaEmail>();

                int? employeeId = null;
                int? contactId = null;

                CS_CallLogResource resource = new CS_CallLogResource()
                {
                    CallLogID = newCallLog.ID,
                    EmployeeID = employeeId,
                    ContactID = contactId,
                    EquipmentID = equipmentWhiteLight.EquipmentID,
                    JobID = newCallLog.JobID,
                    Type = 3,
                    CreatedBy = newCallLog.CreatedBy,
                    CreationDate = DateTime.Now,
                    ModifiedBy = newCallLog.ModifiedBy,
                    ModificationDate = DateTime.Now,
                    Active = true
                };

                resource = _callLogResourceRepository.Add(resource);

                SendNotificationWhiteLight(newCallLog, resource);
            }
            catch (Exception ex)
            {
                throw new Exception("There was an error while trying to save the White Light Resources.", ex);
            }
        }
        public void UpdateStartDatetime(IList<CS_Resource> resourceList)
        {
            IList<CS_CallLogResource> updateCallLogResourceList = new List<CS_CallLogResource>();

            int callTypeID = (int)Globals.CallEntry.CallType.AddedResource;

            for (int i = 0; i < resourceList.Count; i++)
            {
                int? equipmentID = resourceList[i].EquipmentID;
                int? employeeID = resourceList[i].EmployeeID;
                int jobID = resourceList[i].JobID;

                CS_CallLogResource callLogResource = _callLogResourceRepository.ListAll(e => (e.EquipmentID.HasValue && e.EquipmentID == equipmentID) ||
                                                                                         (e.EmployeeID.HasValue && e.EmployeeID == employeeID) &&
                                                                                         e.JobID == jobID &&
                                                                                         e.CS_CallLog.CallTypeID == callTypeID &&
                                                                                         e.Active).LastOrDefault();

                if (null != callLogResource)
                {
                    CS_CallLogResource updatedCallLogResource = new CS_CallLogResource()
                    {
                        ID = callLogResource.ID,
                        CallLogID = callLogResource.CallLogID,
                        EmployeeID = callLogResource.EmployeeID,
                        EquipmentID = callLogResource.EquipmentID,
                        ContactID = null,
                        JobID = callLogResource.JobID,
                        Type = callLogResource.Type,
                        ActionDate = resourceList[i].StartDateTime,
                        CreatedBy = callLogResource.CreatedBy,
                        CreationDate = callLogResource.CreationDate,
                        ModifiedBy = resourceList[i].ModifiedBy,
                        ModificationDate = resourceList[i].ModificationDate,
                        Active = true,
                        CreationID = callLogResource.CreationID,
                        ModificationID = callLogResource.ModificationID
                    };

                    updateCallLogResourceList.Add(updatedCallLogResource);
                }
            }

            _callLogResourceRepository.UpdateList(updateCallLogResourceList);
        }
        public virtual void GenerateAutomaticCallEntryAdd(int jobId, string userName, IList<CS_Resource> addedResourceList, DateTime callDate)
        {
            List<int> employees = new List<int>();
            List<int> equipments = new List<int>();
            List<CS_CallLogResource> callLogResources = new List<CS_CallLogResource>();

            BuildAddedResourceNote(addedResourceList, jobId);
            CS_CallLog addedResourceCallLogEntry = new CS_CallLog()
            {
                JobID = jobId,
                CallTypeID = (int)Globals.CallEntry.CallType.AddedResource,
                PrimaryCallTypeId = (jobId == Globals.GeneralLog.ID ? (int)Globals.CallEntry.PrimaryCallType.ResourceUpdate : (int)Globals.CallEntry.PrimaryCallType.ResourceUpdateAddedResources),
                CallDate = callDate,
                Xml = null,
                Note = _addedResourceBuilder.ToString(),
                CreatedBy = userName,
                CreationDate = DateTime.Now,
                ModifiedBy = userName,
                ModificationDate = DateTime.Now,
                Active = true
            };

            _callLogRepository.Add(addedResourceCallLogEntry);

            foreach (CS_Resource resource in addedResourceList)
            {
                Globals.CallEntry.CallLogResourceType type = Globals.CallEntry.CallLogResourceType.Employee;
                switch ((Globals.ResourceAllocation.ResourceType)resource.Type)
                {
                    case Globals.ResourceAllocation.ResourceType.Employee:
                        type = Globals.CallEntry.CallLogResourceType.Employee;
                        break;
                    case Globals.ResourceAllocation.ResourceType.Equipment:
                        type = Globals.CallEntry.CallLogResourceType.Equipment;
                        break;
                }

                CS_CallLogResource addedResourceEntry = new CS_CallLogResource()
                {
                    CallLogID = addedResourceCallLogEntry.ID,
                    EmployeeID = resource.EmployeeID,
                    EquipmentID = resource.EquipmentID,
                    ContactID = null,
                    JobID = jobId,
                    Type = (int)type,
                    ActionDate = resource.StartDateTime,
                    CreatedBy = addedResourceCallLogEntry.CreatedBy,
                    CreationDate = addedResourceCallLogEntry.CreationDate,
                    ModifiedBy = addedResourceCallLogEntry.ModifiedBy,
                    ModificationDate = addedResourceCallLogEntry.ModificationDate,
                    Active = true,
                    CreationID = addedResourceCallLogEntry.CreationID,
                    ModificationID = addedResourceCallLogEntry.ModificationID
                };

                addedResourceEntry = _callLogResourceRepository.Add(addedResourceEntry);

                callLogResources.Add(addedResourceEntry);

                if (resource.EmployeeID.HasValue)
                    employees.Add(resource.EmployeeID.Value);
                else
                    equipments.Add(resource.EquipmentID.Value);

            }

            employees = addedResourceList.Where(e => e.EmployeeID.HasValue).Select(e => e.EmployeeID.Value).ToList();
            equipments = addedResourceList.Where(e => e.EquipmentID.HasValue).Select(e => e.EquipmentID.Value).ToList();

            SendCallLogNotificationAddedEmails(addedResourceCallLogEntry, callLogResources);

            _callLogModel.VerifyDPICalculate(addedResourceCallLogEntry, employees, equipments);
        }