public void GenerateResourceAllocationReport(string appTempDirectory)
        {
            logger.Info("Reading system settings");
            string       emailClientIP    = ProcessorHelper.GetSettingsValue(ProcessorHelper.EMAIL_PROXY_SERVER);
            string       ownerEmailID     = ProcessorHelper.GetSettingsValue(ProcessorHelper.CONTRACTOR_REQ_EMAIL_OWNER);
            string       templateFilePath = ProcessorHelper.GetSettingsValue(ProcessorHelper.TEMPLATE_FOLDER_PATH) + "\\ResourceAllocationReportTemplate.html";
            string       toEmailID        = ProcessorHelper.GetSettingsValue(ProcessorHelper.MANAGERS_EMAIL_GROUP);
            string       outlookPwd       = ProcessorHelper.GetSettingsValue(ProcessorHelper.EMAIL_OWNERS_PASSWORD);
            string       emailSubject     = "Agilisium - Resource Allocation Report";
            string       bccEmailIDs      = ProcessorHelper.GetSettingsValue(ProcessorHelper.CONTRACTOR_REQ_BCC_RECEIPIENTS);
            EmailHandler emailHandler     = new EmailHandler(ownerEmailID, outlookPwd);

            string emailContent       = GenerateEmailBody(templateFilePath);
            string attachmentFilePath = GenerateAllocationReportAsCsvFile(appTempDirectory);

            logger.Info("Sending email with attachment");
            emailHandler.SendEmail(emailClientIP, toEmailID, emailSubject, emailContent, bccEmailIDs, attachmentFilePath);

            WindowsServiceSettingsDto windowsService = new WindowsServiceSettingsDto
            {
                ExecutionInterval = "Weekly",
                ServiceID         = (int)WindowsServices.WeeklyAllocationsMailer,
                ServiceName       = WindowsServices.WeeklyAllocationsMailer.ToString(),
            };

            settingRepository.UpdateWindowsServiceStatus(windowsService);
        }
        public int ProcessAllocations()
        {
            logger.Info($"Service Execution Time : {DateTime.Today.ToLongTimeString()}");
            int newAllocations = 0;

            try
            {
                List <ProjectAllocationDto> activeAllocations    = allocationRepo.GetAllRecords().ToList();
                List <ProjectAllocationDto> allocationsToProcess = activeAllocations.Where(a => a.AllocationEndDate.Subtract(DateTime.Today).TotalDays <= 31 &&
                                                                                           a.ProjectName.ToLower().Contains("bench") == false).ToList();
                logger.Info($"There are {allocationsToProcess.Count} allocations to be processed");
                foreach (ProjectAllocationDto allocation in allocationsToProcess)
                {
                    logger.Info($"Processing allocation entry with ID {allocation.AllocationEntryID}");
                    if (allocationRepo.AnyOtherActiveAllocation(allocation.AllocationEntryID, allocation.EmployeeID, allocation.AllocationEndDate))
                    {
                        logger.Info("found another allocation with the extended date. Email alert will not be sent");
                        // found another allocation with the extended date. igore this allocation
                        continue;
                    }

                    double daysDifference = allocation.AllocationEndDate.Subtract(DateTime.Today).TotalDays;
                    logger.Info($"Allocation days difference {daysDifference}");
                    if ((daysDifference > 29 && daysDifference < 31) ||
                        (daysDifference > 14 && daysDifference < 16) ||
                        (daysDifference > 4 && daysDifference < 6) ||
                        (daysDifference > 0 && daysDifference < 2))
                    {
                        logger.Info("Matching the criteria. Preparing email content");
                        SendAllocationEmail(allocation);
                        logger.Info("Email sent");
                    }
                    else if (daysDifference < 0 && daysDifference > -2)
                    {
                        logger.Info("Moving the resource under bench project");
                        MoveResourceToBenchProject(allocation.EmployeeID);
                    }
                    else
                    {
                        logger.Info("No Alerts will be sent today (only on 30, 15, 5, 1) ");
                        continue;
                    }

                    WindowsServiceSettingsDto windowsService = new WindowsServiceSettingsDto
                    {
                        ExecutionInterval = "Daily",
                        ServiceID         = (int)WindowsServices.DailyAllocationsUpdater,
                        ServiceName       = WindowsServices.DailyAllocationsUpdater.ToString(),
                    };
                    settingRepository.UpdateWindowsServiceStatus(windowsService);
                }
            }
            catch (Exception exp)
            {
                logger.Error(exp.Message, exp);
            }
            return(newAllocations);
        }
        public void GenerateManagementNotifications(string appTempDirectory, int reportingDay)
        {
            logger.Info("Reading system settings");
            string emailClientIP    = ProcessorHelper.GetSettingsValue(ProcessorHelper.EMAIL_PROXY_SERVER);
            string ownerEmailID     = ProcessorHelper.GetSettingsValue(ProcessorHelper.CONTRACTOR_REQ_EMAIL_OWNER);
            string templateFilePath = ProcessorHelper.GetSettingsValue(ProcessorHelper.TEMPLATE_FOLDER_PATH) + "\\PODWiseEmployees.html";
            string toEmailID        = null;
            string outlookPwd       = ProcessorHelper.GetSettingsValue(ProcessorHelper.EMAIL_OWNERS_PASSWORD);
            string emailSubject     = "RMT Alert - Please Confirm, Employees Under your POD";

            try
            {
                logger.Info("Deleting old files");
                FilesHandler.RemoveAllFilesFromDirectory(appTempDirectory);
            }
            catch (Exception exp)
            {
                logger.Error(exp);
            }

            List <PracticeDto> pods = practiceRepository.GetAll().ToList();

            logger.Info($"There are {pods.Count} PODs");
            foreach (PracticeDto pod in pods)
            {
                logger.Info("Generating CSV file");
                string attachmentFilePath = CreateFileAttachment(appTempDirectory, pod.PracticeID);

                logger.Info("Generating email content");
                string emailContent   = GenerateEmailBody(templateFilePath, pod.PracticeID, pod.PracticeName, pod.ManagerName, reportingDay);
                string managerEmailID = null;
                if (pod.ManagerID.HasValue)
                {
                    managerEmailID = empService.GetByID(pod.ManagerID.Value)?.EmailID;
                }

                if (string.IsNullOrWhiteSpace(managerEmailID))
                {
                    managerEmailID = dmEmailID;
                }
                toEmailID = managerEmailID;

                logger.Info("Sending email with attachment to " + pod.ManagerName);
                EmailHandler emailHandler = new EmailHandler(ownerEmailID, outlookPwd);
                emailHandler.SendEmail(emailClientIP, toEmailID, emailSubject, emailContent, dmEmailID, attachmentFilePath, System.Net.Mail.MailPriority.High);

                WindowsServiceSettingsDto windowsService = new WindowsServiceSettingsDto
                {
                    ExecutionInterval = "Monthly",
                    ServiceID         = (int)WindowsServices.ManagementNotifications,
                    ServiceName       = WindowsServices.ManagementNotifications.ToString(),
                };
                settingRepository.UpdateWindowsServiceStatus(windowsService);
            }
        }