Exemplo n.º 1
0
        //private List<TaskApproval> ProcessApplicantForTaskApprovals(IList<taskapplicant> taskApplicants)
        //{

        //}

        public int AssignTask(AssignTaskRequest taskRequest)
        {
            var userContext         = _commonService.GetCurrentUserContext();
            var dbApprovedApplicant = new approvedapplicant();

            dbApprovedApplicant.ID           = taskRequest.TaskApplicantId;
            dbApprovedApplicant.TASK_ID      = taskRequest.TaskId;
            dbApprovedApplicant.APPLICANT_ID = taskRequest.ApplicantId;
            MapAuditFields <approvedapplicant>(ActionType.Insert, dbApprovedApplicant);
            var result = _requestorRepository.AssignTask(dbApprovedApplicant);

            if (result > 0)
            {
                var task                 = _taskRepository.GetTaskById(taskRequest.TaskId);
                var offering             = _commonService.GetOfferings().Where(x => x.Id == task.OFFERING_ID).Select(x => x.Description).FirstOrDefault();
                var applicant            = _requestorRepository.GetTaskApplicantByApplicantId(taskRequest.TaskApplicantId);
                var applicantUserContext = _commonService.MapDetailsFromDeloitteNetworkWithoutUserContextObject(applicant.user.EMAIL_ID.Split('@')[0]);
                var RMGroupEmailAddress  = _commonService.GetRMGroupEmailAddress(applicantUserContext.Department);

                var ccEmailAddress = taskRequest.TaskTypeId == 1
                    ? $"{userContext.EmailId};{applicant.user.MANAGER_EMAIL_ID};{RMGroupEmailAddress}"
                    : userContext.EmailId;

                var mailMessage  = EmailHelper.AssignNotification(applicant.user.FIRST_NAME + Constants.Space + applicant.user.LAST_NAME, applicant.task.TASK_NAME, applicant.task.PROJECT_NAME, applicant.task.PROJECT_WBS_Code, applicant.user.EMAIL_ID, ccEmailAddress, offering);
                var emailTracker = new EmailTracker
                {
                    ToAddresses = applicant.user.EMAIL_ID,
                    Subject     = mailMessage.Subject,
                    Body        = mailMessage.Body,
                    TaskId      = taskRequest.TaskId,
                    Source      = ApplicationSource.WebApp.ToString()
                };

                if (ccEmailAddress != null)
                {
                    emailTracker.CcAddresses.Add(ccEmailAddress);
                }

                _emailTrackerService.InsertEmail(emailTracker);
            }
            return(result);
        }
        public void Invoke()
        {
            LogMessage("Starting execution of daily consolidated CS task");

            if (NeedsExecution())
            {
                LogMessage("Valid day for execution of consolidated CS task");

                LogMessage($"Date range is { GetExecutionDateRange()}");

                var tasksCreatedFromDateRange =
                    _reportingService.GetNotificationsForCollectiveCSTasks(
                        GetExecutionDateRange());

                if (tasksCreatedFromDateRange == null)
                {
                    LogMessage("No records found for date range");
                    return;
                }

                LogMessage($"Tasks created for date range is {tasksCreatedFromDateRange?.Count()}");

                var notifications = GetNotificationsFromTasks(tasksCreatedFromDateRange);

                LogMessage($"Notifications created for date range is {notifications?.Count()}");

                if (notifications == null)
                {
                    LogMessage("No notifications found");
                    return;
                }

                LogMessage("Sending emails");

                _emailService.SendBulkEmail(notifications);

                foreach (var notification in notifications)
                {
                    var emailTracker = new EmailTracker
                    {
                        Subject      = notification.Subject,
                        ToAddresses  = notification.ToAddresses,
                        Body         = notification.Body,
                        CcAddresses  = notification.CcAddresses,
                        BccAddresses = notification.BccAddresses,
                        Source       = ApplicationSource.Notification.ToString()
                    };

                    _emailTrackerService.InsertEmail(emailTracker);
                }

                LogMessage("Emails sent");
            }
        }
        public void Invoke()
        {
            try
            {
                Console.WriteLine($"Application Started at {DateTime.Now.ToString()}");
                LogMessage($"Application Started at {DateTime.Now.ToString()}");

                var skills
                    = _reportingService.GetSkillsForNewTasksAddeddYesterday();

                if (skills == null ||
                    skills.Count() == 0)
                {
                    Console.WriteLine($"No skills fetched from DB. Process Ended");
                    LogMessage($"No skills fetched from DB. Process Ended");

                    return;
                }

                Console.WriteLine($"Number skills fetched from DB = {skills.Count()}");
                LogMessage($"Number skills fetched from DB = {skills.Count()}");

                var notifications = GetNotificationsFromSkills(skills);

                Console.WriteLine($"Sending bulk emails");
                LogMessage($"Sending bulk emails");

                _emailService.SendBulkEmail(notifications);

                foreach (var notification in notifications)
                {
                    var emailTracker = new EmailTracker
                    {
                        Subject      = notification.Subject,
                        ToAddresses  = notification.ToAddresses,
                        Body         = notification.Body,
                        CcAddresses  = notification.CcAddresses,
                        BccAddresses = notification.BccAddresses,
                        Source       = ApplicationSource.Notification.ToString()
                    };

                    _emailTrackerService.InsertEmail(emailTracker);
                }

                Console.WriteLine($"Sending bulk emails completed");
                LogMessage($"Sending bulk emails completed");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"An error occurred while executing :: {ex.StackTrace}");
                LogMessage($"An error occurred while executing :: {ex.StackTrace}");
            }
        }
        public void Invoke()
        {
            try
            {
                var firmInitiatives = _reportingService.GetFirmInitiativeTasksCreatedYesterday();

                if (firmInitiatives == null || firmInitiatives?.Count() == 0)
                {
                    Console.WriteLine($"No firm initiatives from yesterday. Ending execution");
                    LogMessage($"No firm initiatives from yesterday. Ending execution");

                    return;
                }

                Console.WriteLine($"Number of firm initiatives ={firmInitiatives.Count()}");
                LogMessage($"Number of firm initiatives  ={firmInitiatives.Count()}");

                var notifications = GetNotificationsForNewFirmInitiatives(firmInitiatives);

                Console.WriteLine($"Number of notifications ={notifications.Count()}");
                LogMessage($"Number of notifications  ={notifications.Count()}");

                Console.WriteLine($"Sending bulk emails");
                LogMessage($"Sending bulk emails");

                _emailService.SendBulkEmail(notifications);

                foreach (var notification in notifications)
                {
                    var emailTracker = new EmailTracker
                    {
                        Subject      = notification.Subject,
                        ToAddresses  = notification.ToAddresses,
                        Body         = notification.Body,
                        CcAddresses  = notification.CcAddresses,
                        BccAddresses = notification.BccAddresses,
                        Source       = ApplicationSource.Notification.ToString()
                    };

                    _emailTrackerService.InsertEmail(emailTracker);
                }

                Console.WriteLine($"Sending bulk emails completed");
                LogMessage($"Sending bulk emails completed");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"An error occurred while executing :: {ex.StackTrace}");
                LogMessage($"An error occurred while executing :: {ex.StackTrace}");
            }
        }
Exemplo n.º 5
0
        public int ApplyTask(int taskId, string emailAddress, string statementOfPurpose)
        {
            try
            {
                var user = _commonService.GetCurrentUserContext();

                var taskApplicant = new taskapplicant
                {
                    APPLICANT_ID         = user.UserId,
                    TASK_ID              = taskId,
                    STATUS               = ApplicantStatus.Active.ToString(),
                    STATUS_DATE          = DateTime.Now,
                    STATEMENT_OF_PURPOSE = statementOfPurpose
                };

                MapAuditFields(ActionType.Insert, taskApplicant);

                var result = _contributorRepository.ApplyForTask(taskApplicant);

                if (result > 0)
                {
                    var task = _taskRepository.GetTaskById(taskId);

                    if (string.IsNullOrWhiteSpace(emailAddress))
                    {
                        emailAddress = user.ManagerEmailId;
                    }

                    var managerName = _commonService.GetNameFromEmailId(emailAddress);

                    _userRepository.UpdateManager(user.UserId, managerName, emailAddress);

                    var RMGroupEmailAddress = _commonService.GetRMGroupEmailAddress(user.Department);

                    var offering = _commonService.GetOfferings().Where(x => x.Id == task.OFFERING_ID).Select(x => x.Description).FirstOrDefault();

                    var mailMessage = EmailHelper.ApplyNotification(
                        managerName,
                        $"{user.FirstName}{Constants.Space}{user.LastName}",
                        task.TASK_NAME,
                        task.PROJECT_NAME,
                        $"{task.HOURS.ToString()}h",
                        task.ONBOARDING_DATE.Value.ToShortDateString(),
                        emailAddress,
                        $"{user.EmailId};{RMGroupEmailAddress}",
                        offering);

                    var emailTracker = new EmailTracker
                    {
                        ToAddresses = emailAddress,
                        Subject     = mailMessage.Subject,
                        Body        = mailMessage.Body,
                        TaskId      = taskId,
                        Source      = ApplicationSource.WebApp.ToString()
                    };

                    if (RMGroupEmailAddress != null)
                    {
                        emailTracker.CcAddresses.Add(RMGroupEmailAddress);
                    }

                    _emailTrackerService.InsertEmail(emailTracker);
                }
                return(result);
            }
            catch (Exception ex)
            {
                var logDetails = new DCode.Models.Common.Log {
                    Description = ex.Message, Details = ex.ToString()
                };
                _commonService.LogToDatabase(logDetails);
                return(-1);
            }
        }
Exemplo n.º 6
0
        public int UpsertTask(TaskRequest taskRequest)
        {
            var result = 0;

            if (taskRequest.ActionType == ActionType.Insert)
            {
                taskRequest.WBSCode = string.IsNullOrWhiteSpace(taskRequest.WBSCode)
                    ? "WBS00000-00-00-00-0000"
                    : taskRequest.WBSCode;

                var dbTask = _taskModelFactory.CreateModel <TaskRequest>(taskRequest);
                MapAuditFields <task>(ActionType.Insert, dbTask);
                if (taskRequest.SelectedTaskType == "2" ||
                    taskRequest.SelectedTaskType == "3")
                {
                    if (taskRequest.SkillSet == null ||
                        !taskRequest.SkillSet.Any())
                    {
                        var listOfSkills = new List <int>();

                        var skillName = taskRequest.SelectedTaskType == "2"
                            ? Constants.FirmInitiativeSkillRecord
                            : Constants.IndustryInitiativeSkillRecord;

                        var matchedSkill = _taskRepository.GetSkillByName(skillName);

                        listOfSkills.Add(matchedSkill != null
                            ? matchedSkill.ID
                            : default(int));

                        taskRequest.SkillSet = listOfSkills;
                    }
                }
                var dbTaskSkills = _taskSkillModelFactory.CreateModelList(taskRequest.SkillSet);
                foreach (var dbTaskSkill in dbTaskSkills)
                {
                    MapAuditFields <taskskill>(ActionType.Insert, dbTaskSkill);
                }
                result = _taskRepository.InsertTask(dbTask, dbTaskSkills);

                if (taskRequest.SelectedTaskType == "2" &&
                    result == 2)
                {
                    var currentUser = _commonService.GetCurrentUserContext();

                    var offeringRecipients = _commonService.GetFINotificationRecipientsForOffering(
                        Convert.ToInt32(taskRequest.SelectedOffering));

                    offeringRecipients = offeringRecipients != null && offeringRecipients.Any()
                        ? offeringRecipients
                        : _commonService.GetDefaultConsultingMailboxes();

                    var offering = _commonService.GetOfferings()
                                   .Where(x => x.Id == Convert.ToInt32(taskRequest.SelectedOffering))
                                   .Select(x => x.Description)
                                   .FirstOrDefault();

                    var mailMessage = EmailHelper.PostNewFINotification(taskRequest.ProjectName,
                                                                        taskRequest.Hours.ToString(),
                                                                        taskRequest.Description,
                                                                        taskRequest.OnBoardingDate,
                                                                        currentUser.EmailId,
                                                                        offeringRecipients,
                                                                        offering);
                    var emailTracker = new EmailTracker
                    {
                        ToAddresses = ConfigurationManager.AppSettings["DcodeEmailId"],
                        Subject     = mailMessage.Subject,
                        Body        = mailMessage.Body,
                        TaskId      = taskRequest.Id,
                        Source      = ApplicationSource.WebApp.ToString()
                    };

                    if (currentUser.EmailId != null)
                    {
                        emailTracker.CcAddresses.Add(currentUser.EmailId);
                    }


                    if (offeringRecipients != null && offeringRecipients.Any())
                    {
                        emailTracker.BccAddresses.AddRange(offeringRecipients);
                    }

                    _emailTrackerService.InsertEmail(emailTracker);
                }
            }
            else if (taskRequest.ActionType == ActionType.Update)
            {
                var dbTask = _taskModelFactory.CreateModel <TaskRequest>(taskRequest);
                MapAuditFields <task>(ActionType.Update, dbTask);
                result = _taskRepository.UpdateTask(dbTask);
            }
            return(result);
        }