Пример #1
0
        public void SendEmailAndSmsNotificationToPreferredSubstitute(PreferredSubstituteModel preferredSchoolModel)
        {
            AbsenceModel absenceDetail = _absenceService.GetAbsenceDetailByAbsenceId(preferredSchoolModel.AbsenceId);
            Message      message       = new Message();

            message.ConfirmationNumber = absenceDetail.ConfirmationNumber;
            message.AbsenceId          = absenceDetail.AbsenceId;
            message.StartTime          = DateTime.ParseExact(Convert.ToString(absenceDetail.StartTime), "HH:mm:ss",
                                                             CultureInfo.InvariantCulture).ToSubzzTime();
            message.EndTime = DateTime.ParseExact(Convert.ToString(absenceDetail.EndTime), "HH:mm:ss",
                                                  CultureInfo.InvariantCulture).ToSubzzTime();
            message.StartDate    = Convert.ToDateTime(absenceDetail.StartDate).ToString("D");
            message.EndDate      = Convert.ToDateTime(absenceDetail.EndDate).ToString("D");
            message.StartTimeSMS = DateTime.ParseExact(Convert.ToString(absenceDetail.StartTime), "HH:mm:ss",
                                                       CultureInfo.InvariantCulture).ToSubzzTimeForSms();
            message.EndTimeSMS = DateTime.ParseExact(Convert.ToString(absenceDetail.EndTime), "HH:mm:ss",
                                                     CultureInfo.InvariantCulture).ToSubzzTimeForSms();
            if (message.StartDate == message.EndDate)
            {
                message.DateToDisplayInSMS = Convert.ToDateTime(absenceDetail.StartDate).ToSubzzDateForSMS();
            }
            else
            {
                message.DateToDisplayInSMS = Convert.ToDateTime(absenceDetail.StartDate).ToSubzzShortDateForSMS() + "-" + Convert.ToDateTime(absenceDetail.EndDate).ToSubzzDateForSMS();
            }
            if (!string.IsNullOrEmpty(absenceDetail.OrganizationPhoneNumber) && absenceDetail.OrganizationPhoneNumber.Length > 5)
            {
                message.FromPhoneNumber = absenceDetail.OrganizationPhoneNumber;
            }
            else
            {
                message.FromPhoneNumber = absenceDetail.DistrictPhoneNumber;
            }
            message.EmployeeName     = absenceDetail.EmployeeName;
            message.Position         = absenceDetail.PositionDescription;
            message.Subject          = absenceDetail.SubjectDescription;
            message.Grade            = absenceDetail.Grade;
            message.Location         = absenceDetail.AbsenceLocation;
            message.School           = absenceDetail.OrganizationName;
            message.Notes            = absenceDetail.SubstituteNotes;
            message.SubstituteName   = absenceDetail.SubstituteName;
            message.Reason           = absenceDetail.AbsenceReasonDescription;
            message.Duration         = absenceDetail.DurationType == 1 ? "Full Day" : absenceDetail.DurationType == 2 ? "First Half" : absenceDetail.DurationType == 3 ? "Second Half" : "Custom";
            message.AttachedFileName = absenceDetail.AttachedFileName;
            message.FileContentType  = absenceDetail.FileContentType;
            message.Photo            = absenceDetail.EmployeeProfilePicUrl;
            message.Password         = preferredSchoolModel.Password;
            message.UserName         = preferredSchoolModel.SubstituteName;
            message.SendTo           = preferredSchoolModel.EmailId;
            message.PhoneNumber      = preferredSchoolModel.SubstitutePhoneNumber;
            //For Substitutes
            message.TemplateId = 1;
            CommunicationContainer.EmailProcessor.ProcessAsync(message, (MailTemplateEnums)message.TemplateId);
            CommunicationContainer.SMSProcessor.Process(message, (MailTemplateEnums)message.TemplateId);
        }
        public IActionResult ResendJob([FromBody] AbsenceModel model)
        {
            try
            {
                AbsenceModel absenceDetail = _absenceService.GetAbsenceDetailByAbsenceId(model.AbsenceId);
                IEnumerable <SubzzV2.Core.Entities.User> users = _service.GetAdminListByAbsenceId(model.AbsenceId);
                Message message = new Message();
                message.ConfirmationNumber = absenceDetail.ConfirmationNumber;
                message.StartTime          = DateTime.ParseExact(Convert.ToString(absenceDetail.StartTime), "HH:mm:ss",
                                                                 CultureInfo.InvariantCulture).ToSubzzTime();
                message.EndTime = DateTime.ParseExact(Convert.ToString(absenceDetail.EndTime), "HH:mm:ss",
                                                      CultureInfo.InvariantCulture).ToSubzzTime();
                message.StartDate    = Convert.ToDateTime(absenceDetail.StartDate).ToString("D");
                message.EndDate      = Convert.ToDateTime(absenceDetail.EndDate).ToString("D");
                message.StartTimeSMS = DateTime.ParseExact(Convert.ToString(absenceDetail.StartTime), "HH:mm:ss",
                                                           CultureInfo.InvariantCulture).ToSubzzTimeForSms();
                message.EndTimeSMS = DateTime.ParseExact(Convert.ToString(absenceDetail.EndTime), "HH:mm:ss",
                                                         CultureInfo.InvariantCulture).ToSubzzTimeForSms();
                if (message.StartDate == message.EndDate)
                {
                    message.DateToDisplayInSMS = Convert.ToDateTime(absenceDetail.StartDate).ToSubzzDateForSMS();
                }
                else
                {
                    message.DateToDisplayInSMS = Convert.ToDateTime(absenceDetail.StartDate).ToSubzzShortDateForSMS() + "-" + Convert.ToDateTime(absenceDetail.EndDate).ToSubzzDateForSMS();
                }
                message.EmployeeName   = absenceDetail.EmployeeName;
                message.Position       = absenceDetail.PositionDescription;
                message.Subject        = absenceDetail.SubjectDescription;
                message.Grade          = absenceDetail.Grade;
                message.Location       = absenceDetail.AbsenceLocation;
                message.Notes          = absenceDetail.SubstituteNotes;
                message.SubstituteName = absenceDetail.SubstituteName;
                message.School         = absenceDetail.OrganizationName;
                message.Photo          = absenceDetail.EmployeeProfilePicUrl;
                message.Duration       = absenceDetail.DurationType == 1 ? "Full Day" : absenceDetail.DurationType == 2 ? "First Half" : absenceDetail.DurationType == 3 ? "Second Half" : "Custom";

                message.TemplateId = 10;
                message.Photo      = absenceDetail.EmployeeProfilePicUrl;
                Task.Run(() => SendEmails(users, message, absenceDetail));
                _absenceService.UpdateAbsenceResendCounter(model.AbsenceId);
            }
            catch (Exception ex)
            {
            }
            finally
            {
            }
            return(Json("success"));
        }
Пример #3
0
        public async Task <string> AcceptJob(int AbsenceId, string SubstituteId, string AcceptVia)
        {
            try
            {
                string AcceptJob = await _jobService.AcceptJob(AbsenceId, SubstituteId, AcceptVia);

                if (AcceptJob == "success")
                {
                    //Send Notification here
                    AbsenceModel absenceDetail = _absenceService.GetAbsenceDetailByAbsenceId(AbsenceId);
                    IEnumerable <SubzzV2.Core.Entities.User> users = _userService.GetAdminListByAbsenceId(AbsenceId);
                    Message message = new Message();
                    message.ConfirmationNumber = absenceDetail.ConfirmationNumber;
                    message.AbsenceId          = absenceDetail.AbsenceId;
                    message.StartTime          = DateTime.ParseExact(Convert.ToString(absenceDetail.StartTime), "HH:mm:ss",
                                                                     CultureInfo.InvariantCulture).ToSubzzTime();
                    message.EndTime = DateTime.ParseExact(Convert.ToString(absenceDetail.EndTime), "HH:mm:ss",
                                                          CultureInfo.InvariantCulture).ToSubzzTime();
                    message.StartDate    = Convert.ToDateTime(absenceDetail.StartDate).ToString("D");
                    message.EndDate      = Convert.ToDateTime(absenceDetail.EndDate).ToString("D");
                    message.StartTimeSMS = DateTime.ParseExact(Convert.ToString(absenceDetail.StartTime), "HH:mm:ss",
                                                               CultureInfo.InvariantCulture).ToSubzzTimeForSms();
                    message.EndTimeSMS = DateTime.ParseExact(Convert.ToString(absenceDetail.EndTime), "HH:mm:ss",
                                                             CultureInfo.InvariantCulture).ToSubzzTimeForSms();
                    if (message.StartDate == message.EndDate)
                    {
                        message.DateToDisplayInSMS = Convert.ToDateTime(absenceDetail.StartDate).ToSubzzDateForSMS();
                    }
                    else
                    {
                        message.DateToDisplayInSMS = Convert.ToDateTime(absenceDetail.StartDate).ToSubzzShortDateForSMS() + "-" + Convert.ToDateTime(absenceDetail.EndDate).ToSubzzDateForSMS();
                    }
                    if (!string.IsNullOrEmpty(absenceDetail.OrganizationPhoneNumber) && absenceDetail.OrganizationPhoneNumber.Length > 5)
                    {
                        message.FromPhoneNumber = absenceDetail.OrganizationPhoneNumber;
                    }
                    else
                    {
                        message.FromPhoneNumber = absenceDetail.DistrictPhoneNumber;
                    }
                    message.EmployeeName     = absenceDetail.EmployeeName;
                    message.Position         = absenceDetail.PositionDescription;
                    message.Subject          = absenceDetail.SubjectDescription;
                    message.Grade            = absenceDetail.Grade;
                    message.Location         = absenceDetail.AbsenceLocation;
                    message.School           = absenceDetail.OrganizationName;
                    message.Notes            = absenceDetail.SubstituteNotes;
                    message.SubstituteName   = absenceDetail.SubstituteName;
                    message.Reason           = absenceDetail.AbsenceReasonDescription;
                    message.Photo            = absenceDetail.SubstituteProfilePicUrl;
                    message.AttachedFileName = absenceDetail.AttachedFileName;
                    message.FileContentType  = absenceDetail.FileContentType;
                    message.Duration         = absenceDetail.DurationType == 1 ? "Full Day" : absenceDetail.DurationType == 2 ? "First Half" : absenceDetail.DurationType == 3 ? "Second Half" : "Custom";
                    //Notification notification = new Notification();
                    Task.Run(() => SendJobAcceptEmails(users, message, absenceDetail));

                    // Audit Log
                    var audit = new AuditLog
                    {
                        UserId         = CurrentUser.Id,
                        EntityId       = absenceDetail.ConfirmationNumber.ToString(),
                        EntityType     = AuditLogs.EntityType.Absence,
                        ActionType     = AuditLogs.ActionType.Accepted,
                        DistrictId     = CurrentUser.DistrictId,
                        OrganizationId = CurrentUser.OrganizationId == "-1" ? null : CurrentUser.OrganizationId
                    };
                    _audit.InsertAuditLog(audit);
                }
                return(AcceptJob);
            }
            catch (Exception ex)
            {
            }
            return(null);
        }
Пример #4
0
        public async Task SendNotificationsOnJobApprovedOrDenied(LeaveRequestModel leave)
        {
            AbsenceModel absenceDetail = _absenceService.GetAbsenceDetailByAbsenceId(Convert.ToInt32(leave.AbsenceId));

            Subzz.Integration.Core.Domain.Message message = new Subzz.Integration.Core.Domain.Message();
            message.AbsenceId = absenceDetail.AbsenceId;
            message.StartTime = DateTime.ParseExact(Convert.ToString(absenceDetail.StartTime), "HH:mm:ss",
                                                    CultureInfo.InvariantCulture).ToSubzzTime();
            message.EndTime = DateTime.ParseExact(Convert.ToString(absenceDetail.EndTime), "HH:mm:ss",
                                                  CultureInfo.InvariantCulture).ToSubzzTime();
            message.StartDate      = Convert.ToDateTime(absenceDetail.StartDate).ToString("D");
            message.EndDate        = Convert.ToDateTime(absenceDetail.EndDate).ToString("D");
            message.EmployeeName   = absenceDetail.EmployeeName;
            message.Position       = absenceDetail.PositionDescription;
            message.Subject        = absenceDetail.SubjectDescription;
            message.Grade          = absenceDetail.Grade;
            message.Location       = absenceDetail.AbsenceLocation;
            message.Notes          = absenceDetail.SubstituteNotes;
            message.SubstituteName = absenceDetail.SubstituteName;
            message.Reason         = absenceDetail.AbsenceReasonDescription;
            message.ApprovedBy     = _userService.GetUserDetail(leave.ApprovedBy).FirstName;
            message.Duration       = absenceDetail.DurationType == 1 ? "Full Day" : absenceDetail.DurationType == 2 ? "First Half" : absenceDetail.DurationType == 3 ? "Second Half" : "Custom";
            var user = _userService.GetUserDetail(absenceDetail.EmployeeId);

            if (leave.IsApproved)
            {
                message.TemplateId = 16;
            }
            else
            {
                message.TemplateId = 19;
            }
            message.Photo = absenceDetail.EmployeeProfilePicUrl;
            try
            {
                message.Password = user.Password;
                message.UserName = user.FirstName;
                message.SendTo   = user.Email;
                await CommunicationContainer.EmailProcessor.ProcessAsync(message, (MailTemplateEnums)message.TemplateId);
            }
            catch (Exception ex)
            {
            }

            if (leave.IsApproved)
            {
                IEnumerable <SubzzV2.Core.Entities.User> users = _userService.GetAdminListByAbsenceId(Convert.ToInt32(leave.AbsenceId));
                foreach (var User in users)
                {
                    try
                    {
                        message.Password = User.Password;
                        message.UserName = User.FirstName;
                        message.SendTo   = User.Email;
                        //For Substitutes
                        if (User.RoleId == 4)
                        {
                            message.TemplateId = 1;
                            await CommunicationContainer.EmailProcessor.ProcessAsync(message, (MailTemplateEnums)message.TemplateId);
                        }
                        else if (User.RoleId == 3)
                        {
                            message.TemplateId = 10;
                            await CommunicationContainer.EmailProcessor.ProcessAsync(message, (MailTemplateEnums)message.TemplateId);
                        }
                        //For Admins
                        else
                        {
                            message.TemplateId = 2;
                            await CommunicationContainer.EmailProcessor.ProcessAsync(message, (MailTemplateEnums)message.TemplateId);
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
        }
Пример #5
0
        public async Task <TwiMLResult> RecieveSms(SmsRequest incomingMessage)
        {
            var messagingResponse = new MessagingResponse();

            //Confirmation Number is on 0 Index and (A => Accept, D => Decline, R => Release) are on first Index
            string[] body = incomingMessage.Body.Split(' ');
            if (body.Length == 2)
            {
                var AbsenceId = _absenceService.GetAbsenceIdByConfirmationNumber(body[0]);
                if (AbsenceId == 0)
                {
                    //CommunicationContainer.SMSProcessor.Process(incomingMessage.From, incomingMessage.To, "Invalid entry! Please enter correct Job ID", AbsenceId);
                    messagingResponse.Message("Invalid entry! Please enter correct Job ID.");
                    return(TwiML(messagingResponse));
                }
                var userId = _userService.GetUserIdByPhoneNumber(incomingMessage.From);
                if (string.IsNullOrEmpty(userId))
                {
                    //CommunicationContainer.SMSProcessor.Process(incomingMessage.From, incomingMessage.To, "You're not register user", AbsenceId);
                    messagingResponse.Message("You're not register user");
                    return(TwiML(messagingResponse));
                }
                var absenceDetail = _absenceService.GetAbsenceDetailByAbsenceId(AbsenceId);
                if (absenceDetail != null && absenceDetail.AbsenceId > 0)
                {
                    if (body[1].ToLower() == "a")
                    {
                        string status = await _jobService.AcceptJob(absenceDetail.AbsenceId, userId, "Sms");

                        if (status.ToLower() == "success")
                        {
                            IEnumerable <SubzzV2.Core.Entities.User> users = _userService.GetAdminListByAbsenceId(AbsenceId);
                            Message message = new Message();
                            message.ConfirmationNumber = absenceDetail.ConfirmationNumber;
                            message.StartTime          = DateTime.ParseExact(Convert.ToString(absenceDetail.StartTime), "HH:mm:ss",
                                                                             CultureInfo.InvariantCulture).ToSubzzTime();
                            message.EndTime = DateTime.ParseExact(Convert.ToString(absenceDetail.EndTime), "HH:mm:ss",
                                                                  CultureInfo.InvariantCulture).ToSubzzTime();
                            message.StartDate = Convert.ToDateTime(absenceDetail.StartDate).ToString("D");
                            message.EndDate   = Convert.ToDateTime(absenceDetail.EndDate).ToString("D");

                            message.StartTimeSMS = DateTime.ParseExact(Convert.ToString(absenceDetail.StartTime), "HH:mm:ss",
                                                                       CultureInfo.InvariantCulture).ToSubzzTimeForSms();
                            message.EndTimeSMS = DateTime.ParseExact(Convert.ToString(absenceDetail.EndTime), "HH:mm:ss",
                                                                     CultureInfo.InvariantCulture).ToSubzzTimeForSms();
                            if (message.StartDate == message.EndDate)
                            {
                                message.DateToDisplayInSMS = Convert.ToDateTime(absenceDetail.StartDate).ToSubzzDateForSMS();
                            }
                            else
                            {
                                message.DateToDisplayInSMS = Convert.ToDateTime(absenceDetail.StartDate).ToSubzzShortDateForSMS() + "-" + Convert.ToDateTime(absenceDetail.EndDate).ToSubzzDateForSMS();
                            }
                            if (!string.IsNullOrEmpty(absenceDetail.OrganizationPhoneNumber) && absenceDetail.OrganizationPhoneNumber.Length > 5)
                            {
                                message.FromPhoneNumber = absenceDetail.OrganizationPhoneNumber;
                            }
                            else
                            {
                                message.FromPhoneNumber = absenceDetail.DistrictPhoneNumber;
                            }
                            message.EmployeeName   = absenceDetail.EmployeeName;
                            message.Position       = absenceDetail.PositionDescription;
                            message.Subject        = absenceDetail.SubjectDescription;
                            message.Grade          = absenceDetail.Grade;
                            message.Location       = absenceDetail.AbsenceLocation;
                            message.School         = absenceDetail.OrganizationName;
                            message.Notes          = absenceDetail.SubstituteNotes;
                            message.SubstituteName = absenceDetail.SubstituteName;
                            message.Reason         = absenceDetail.AbsenceReasonDescription;
                            message.Photo          = absenceDetail.EmployeeProfilePicUrl;
                            message.Duration       = absenceDetail.DurationType == 1 ? "Full Day" : absenceDetail.DurationType == 2 ? "First Half" : absenceDetail.DurationType == 3 ? "Second Half" : "Custom";
                            //Notification notification = new Notification();
                            Task.Run(() => SendJobAcceptEmails(users, message));

                            // Audit Log
                            var audit = new AuditLog
                            {
                                UserId         = userId,
                                EntityId       = absenceDetail.ConfirmationNumber.ToString(),
                                EntityType     = AuditLogs.EntityType.Absence,
                                ActionType     = AuditLogs.ActionType.Accepted,
                                DistrictId     = absenceDetail.DistrictId,
                                OrganizationId = absenceDetail.OrganizationId == "-1" ? null : absenceDetail.OrganizationId
                            };
                            _audit.InsertAuditLog(audit);
                        }
                        else if (status.ToLower() == "blocked")
                        {
                            //CommunicationContainer.SMSProcessor.Process(incomingMessage.From, incomingMessage.To, "You Are Blocked By Employee To Accept This Job", AbsenceId);
                            messagingResponse.Message("You Are Blocked By Employee To Accept This Job");
                        }
                        else if (status.ToLower() == "cancelled")
                        {
                            //CommunicationContainer.SMSProcessor.Process(incomingMessage.From, incomingMessage.To, "Job Has Been Cancelled", AbsenceId);
                            messagingResponse.Message("Job Has Been Cancelled");
                        }
                        else if (status.ToLower() == "accepted")
                        {
                            //CommunicationContainer.SMSProcessor.Process(incomingMessage.From, incomingMessage.To, "Job Already Accepted", AbsenceId);
                            messagingResponse.Message("Job Already Accepted");
                        }
                        else if (status.ToLower() == "conflict")
                        {
                            //CommunicationContainer.SMSProcessor.Process(incomingMessage.From, incomingMessage.To, "Already Accepted Job on This Date", AbsenceId);
                            messagingResponse.Message("Already Accepted Job on This Date");
                        }
                        else if (status.ToLower() == "declined")
                        {
                            //CommunicationContainer.SMSProcessor.Process(incomingMessage.From, incomingMessage.To, "Declined Successfully", AbsenceId);
                            messagingResponse.Message("Declined Successfully");
                        }
                        else if (status.ToLower() == "unavailable")
                        {
                            //CommunicationContainer.SMSProcessor.Process(incomingMessage.From, incomingMessage.To, "You are unavailable", AbsenceId);
                            messagingResponse.Message("You are unavailable");
                        }
                        else
                        {
                            //CommunicationContainer.SMSProcessor.Process(incomingMessage.From, incomingMessage.To, "Problem Occured While Process you Request.Please Try Again Later", AbsenceId);
                            messagingResponse.Message("Problem Occured While Process your Request.Please Try Again Later");
                        }
                    }
                    else if (body[1].ToLower() == "d")
                    {
                        // Audit Log
                        var audit = new AuditLog
                        {
                            UserId         = userId,
                            EntityId       = absenceDetail.ConfirmationNumber.ToString(),
                            EntityType     = AuditLogs.EntityType.Absence,
                            ActionType     = AuditLogs.ActionType.Declined,
                            DistrictId     = absenceDetail.DistrictId,
                            OrganizationId = absenceDetail.OrganizationId == "-1" ? null : absenceDetail.OrganizationId
                        };
                        _audit.InsertAuditLog(audit);
                        IEnumerable <SubzzV2.Core.Entities.User> users = _userService.GetAdminListByAbsenceId(AbsenceId);
                        Message message = new Message();
                        message.ConfirmationNumber = absenceDetail.ConfirmationNumber;
                        message.StartTime          = DateTime.ParseExact(Convert.ToString(absenceDetail.StartTime), "HH:mm:ss",
                                                                         CultureInfo.InvariantCulture).ToSubzzTime();
                        message.EndTime = DateTime.ParseExact(Convert.ToString(absenceDetail.EndTime), "HH:mm:ss",
                                                              CultureInfo.InvariantCulture).ToSubzzTime();
                        message.StartDate = Convert.ToDateTime(absenceDetail.StartDate).ToString("D");
                        message.EndDate   = Convert.ToDateTime(absenceDetail.EndDate).ToString("D");

                        message.StartTimeSMS = DateTime.ParseExact(Convert.ToString(absenceDetail.StartTime), "HH:mm:ss",
                                                                   CultureInfo.InvariantCulture).ToSubzzTimeForSms();
                        message.EndTimeSMS = DateTime.ParseExact(Convert.ToString(absenceDetail.EndTime), "HH:mm:ss",
                                                                 CultureInfo.InvariantCulture).ToSubzzTimeForSms();
                        if (message.StartDate == message.EndDate)
                        {
                            message.DateToDisplayInSMS = Convert.ToDateTime(absenceDetail.StartDate).ToSubzzDateForSMS();
                        }
                        else
                        {
                            message.DateToDisplayInSMS = Convert.ToDateTime(absenceDetail.StartDate).ToSubzzShortDateForSMS() + "-" + Convert.ToDateTime(absenceDetail.EndDate).ToSubzzDateForSMS();
                        }
                        if (!string.IsNullOrEmpty(absenceDetail.OrganizationPhoneNumber) && absenceDetail.OrganizationPhoneNumber.Length > 5)
                        {
                            message.FromPhoneNumber = absenceDetail.OrganizationPhoneNumber;
                        }
                        else
                        {
                            message.FromPhoneNumber = absenceDetail.DistrictPhoneNumber;
                        }
                        message.EmployeeName   = absenceDetail.EmployeeName;
                        message.Position       = absenceDetail.PositionDescription;
                        message.Subject        = absenceDetail.SubjectDescription;
                        message.Grade          = absenceDetail.Grade;
                        message.Location       = absenceDetail.AbsenceLocation;
                        message.School         = absenceDetail.OrganizationName;
                        message.Notes          = absenceDetail.SubstituteNotes;
                        message.SubstituteName = absenceDetail.SubstituteName;
                        message.Photo          = absenceDetail.EmployeeProfilePicUrl;
                        message.Duration       = absenceDetail.DurationType == 1 ? "Full Day" : absenceDetail.DurationType == 2 ? "First Half" : absenceDetail.DurationType == 3 ? "Second Half" : "Custom";
                        //Notification notification = new Notification();
                        Task.Run(() => SendJobDeclinEmails(users, message));
                        //messagingResponse.Message("Job Decline Successfully");
                    }
                    else if (body[1].ToLower() == "r")
                    {
                        var acceptedJobs = await _jobService.GetAvailableJobs(absenceDetail.StartDate, absenceDetail.EndDate, userId, absenceDetail.OrganizationId, absenceDetail.DistrictId, 2, false);

                        var IsAcceptedJob = acceptedJobs.ToList().Where(absence => absence.AbsenceId == AbsenceId).FirstOrDefault();
                        if (IsAcceptedJob.AbsenceId > 0)
                        {
                            _absenceService.UpdateAbsenceStatus(AbsenceId, 1, DateTime.Now, userId);
                            var audit = new AuditLog
                            {
                                UserId         = userId,
                                EntityId       = absenceDetail.ConfirmationNumber.ToString(),
                                EntityType     = AuditLogs.EntityType.Absence,
                                ActionType     = AuditLogs.ActionType.Released,
                                DistrictId     = absenceDetail.DistrictId,
                                OrganizationId = absenceDetail.OrganizationId == "-1" ? null : absenceDetail.OrganizationId
                            };
                            _audit.InsertAuditLog(audit);
                            Task.Run(() => SendNotificationsOnJobReleased(AbsenceId));
                            CommunicationContainer.SMSProcessor.Process(incomingMessage.From, incomingMessage.To, "Job Release Successfully.", AbsenceId);
                            //messagingResponse.Message("Job Release Successfully");
                        }
                        else
                        {
                            //CommunicationContainer.SMSProcessor.Process(incomingMessage.From, incomingMessage.To, "You are not authorized to reject this job.", AbsenceId);
                            messagingResponse.Message("You are not authorized to reject this job.");
                        }
                    }
                }
                else
                {
                    //CommunicationContainer.SMSProcessor.Process(incomingMessage.From, incomingMessage.To, "Invalid entry! Please enter correct Job ID", AbsenceId);
                    messagingResponse.Message("Invalid entry! Please enter correct Job ID.");
                }
            }
            else
            {
                //CommunicationContainer.SMSProcessor.Process(incomingMessage.From, incomingMessage.To, "Invalid Format!", Convert.ToInt32(body[0]));
                messagingResponse.Message("Not a valid format.");
            }
            return(TwiML(messagingResponse));
        }
Пример #6
0
        async Task SendNotificationsOnJobApprovedOrDenied(LeaveRequestModel leave)
        {
            AbsenceModel absenceDetail = _absenceService.GetAbsenceDetailByAbsenceId(Convert.ToInt32(leave.AbsenceId));
            Message      message       = new Message();

            message.ConfirmationNumber = absenceDetail.ConfirmationNumber;
            message.AbsenceId          = absenceDetail.AbsenceId;
            message.StartTime          = DateTime.ParseExact(Convert.ToString(absenceDetail.StartTime), "HH:mm:ss",
                                                             CultureInfo.InvariantCulture).ToSubzzTime();
            message.EndTime = DateTime.ParseExact(Convert.ToString(absenceDetail.EndTime), "HH:mm:ss",
                                                  CultureInfo.InvariantCulture).ToSubzzTime();
            message.StartDate    = Convert.ToDateTime(absenceDetail.StartDate).ToString("D");
            message.EndDate      = Convert.ToDateTime(absenceDetail.EndDate).ToString("D");
            message.StartTimeSMS = DateTime.ParseExact(Convert.ToString(absenceDetail.StartTime), "HH:mm:ss",
                                                       CultureInfo.InvariantCulture).ToSubzzTimeForSms();
            message.EndTimeSMS = DateTime.ParseExact(Convert.ToString(absenceDetail.EndTime), "HH:mm:ss",
                                                     CultureInfo.InvariantCulture).ToSubzzTimeForSms();
            if (message.StartDate == message.EndDate)
            {
                message.DateToDisplayInSMS = Convert.ToDateTime(absenceDetail.StartDate).ToSubzzDateForSMS();
            }
            else
            {
                message.DateToDisplayInSMS = Convert.ToDateTime(absenceDetail.StartDate).ToSubzzShortDateForSMS() + "-" + Convert.ToDateTime(absenceDetail.EndDate).ToSubzzDateForSMS();
            }
            if (!string.IsNullOrEmpty(absenceDetail.OrganizationPhoneNumber) && absenceDetail.OrganizationPhoneNumber.Length > 5)
            {
                message.FromPhoneNumber = absenceDetail.OrganizationPhoneNumber;
            }
            else
            {
                message.FromPhoneNumber = absenceDetail.DistrictPhoneNumber;
            }
            message.EmployeeName     = absenceDetail.EmployeeName;
            message.Position         = absenceDetail.PositionDescription;
            message.Subject          = absenceDetail.SubjectDescription;
            message.Grade            = absenceDetail.Grade;
            message.Location         = absenceDetail.AbsenceLocation;
            message.School           = absenceDetail.OrganizationName;
            message.Notes            = absenceDetail.SubstituteNotes;
            message.SubstituteName   = absenceDetail.SubstituteName;
            message.Reason           = absenceDetail.AbsenceReasonDescription;
            message.AttachedFileName = absenceDetail.AttachedFileName;
            message.FileContentType  = absenceDetail.FileContentType;
            message.ApprovedBy       = _userService.GetUserDetail(leave.ApprovedBy).FirstName;
            message.Duration         = absenceDetail.DurationType == 1 ? "Full Day" : absenceDetail.DurationType == 2 ? "First Half" : absenceDetail.DurationType == 3 ? "Second Half" : "Custom";
            var employeeDetail = _userService.GetUserDetail(absenceDetail.EmployeeId);

            if (leave.IsApproved)
            {
                message.TemplateId = 16;
            }
            else
            {
                message.TemplateId = 19;
            }
            message.Photo = absenceDetail.EmployeeProfilePicUrl;
            try
            {
                message.Password = employeeDetail.Password;
                message.UserName = employeeDetail.FirstName;
                message.SendTo   = employeeDetail.Email;
                if (employeeDetail.IsSubscribedEmail)
                {
                    var events         = _userService.GetSubstituteNotificationEvents(employeeDetail.UserId);
                    var jobPostedEvent = events.Where(x => x.EventId == 1).First();
                    if (leave.IsApproved)
                    {
                        if (jobPostedEvent.EmailAlert)
                        {
                            await CommunicationContainer.EmailProcessor.ProcessAsync(message, (MailTemplateEnums)message.TemplateId);
                        }
                    }
                    else
                    {
                        await CommunicationContainer.EmailProcessor.ProcessAsync(message, (MailTemplateEnums)message.TemplateId);
                    }
                }
            }
            catch (Exception ex)
            {
            }

            if (leave.IsApproved)
            {
                IEnumerable <SubzzV2.Core.Entities.User> users = _userService.GetAdminListByAbsenceId(Convert.ToInt32(leave.AbsenceId));
                foreach (var user in users)
                {
                    try
                    {
                        message.Password = user.Password;
                        message.UserName = user.FirstName;
                        message.SendTo   = user.Email;
                        //For Substitutes on In case of direct Assign
                        if (user.RoleId == 4 && absenceDetail.AbsenceType == 2 && absenceDetail.SubstituteRequired)
                        {
                            message.TemplateId = 7;
                            var events         = _userService.GetSubstituteNotificationEvents(user.UserId);
                            var jobPostedEvent = events.Where(x => x.EventId == 5).First();
                            var grade          = _userService.GetGradeLevelsForNotification(user.UserId);
                            var isGradeEnabled = grade.Where(x => x.TeachingLevelId == absenceDetail.GradeId).FirstOrDefault();
                            var sub            = _userService.GetSubjectsForNotifications(user.UserId);
                            var subjects       = sub.Where(x => x.TeacherSpecialityId == absenceDetail.SpecialityTypeId).FirstOrDefault();
                            var cat            = _userService.GetSubstituteCategories(user.UserId);
                            var categories     = cat.Where(x => x.TypeId == absenceDetail.PositionId).FirstOrDefault();

                            if (user.IsSubscribedEmail && jobPostedEvent.EmailAlert && (isGradeEnabled != null ? isGradeEnabled.GradeNotification : true) &&
                                (subjects != null ? subjects.SubjectNotification : true) && (absenceDetail.OnlyCertified ? user.IsCertified == 1 : true) &&
                                (categories != null ? categories.IsNotificationSend : true))
                            {
                                if (absenceDetail.OrganizationId != "-1")
                                {
                                    var subSchools      = _userService.GetSubstitutePreferredSchools(user.UserId);
                                    var isSchoolEnabled = subSchools.Where(x => x.OrganizationId == absenceDetail.OrganizationId).First();
                                    if (isSchoolEnabled.IsEnabled)
                                    {
                                        await CommunicationContainer.EmailProcessor.ProcessAsync(message, (MailTemplateEnums)message.TemplateId);
                                    }
                                }
                                else
                                {
                                    await CommunicationContainer.EmailProcessor.ProcessAsync(message, (MailTemplateEnums)message.TemplateId);
                                }
                            }

                            if (user.IsSubscribedSMS && jobPostedEvent.TextAlert && (isGradeEnabled != null ? isGradeEnabled.GradeNotification : true) &&
                                (subjects != null ? subjects.SubjectNotification : true) && (absenceDetail.OnlyCertified ? user.IsCertified == 1 : true) &&
                                (categories != null ? categories.IsNotificationSend : true))
                            {
                                message.PhoneNumber = user.PhoneNumber;
                                if (absenceDetail.OrganizationId != "-1")
                                {
                                    var subSchools      = _userService.GetSubstitutePreferredSchools(user.UserId);
                                    var isSchoolEnabled = subSchools.Where(x => x.OrganizationId == absenceDetail.OrganizationId).First();
                                    if (isSchoolEnabled.IsEnabled)
                                    {
                                        message.PhoneNumber = user.PhoneNumber;
                                        CommunicationContainer.SMSProcessor.Process(message, (MailTemplateEnums)message.TemplateId);
                                    }
                                }
                                else
                                {
                                    CommunicationContainer.SMSProcessor.Process(message, (MailTemplateEnums)message.TemplateId);
                                }
                            }
                            //var events = _userService.GetSubstituteNotificationEvents(user.UserId);
                            //var jobPostedEvent = events.Where(x => x.EventId == 5).First();
                            //message.TemplateId = 7;
                            //if (user.IsSubscribedEmail)
                            //{
                            //    if (jobPostedEvent.EmailAlert)
                            //    {
                            //        message.PhoneNumber = user.PhoneNumber;
                            //        var sub = _userService.GetSubjectsForNotifications(user.UserId);
                            //        var subjects = sub.Where(x => x.TeacherSpecialityId == absenceDetail.SpecialityTypeId).FirstOrDefault();
                            //        if (absenceDetail.OnlySubjectSpecialist && subjects != null ? subjects.SubjectNotification : true &&
                            //            absenceDetail.OnlyCertified ? user.IsCertified == 1 : true)
                            //            await CommunicationContainer.EmailProcessor.ProcessAsync(message, (MailTemplateEnums)message.TemplateId);
                            //    }
                            //}

                            //if (user.IsSubscribedSMS)
                            //{
                            //    if (jobPostedEvent.TextAlert)
                            //    {
                            //        message.PhoneNumber = user.PhoneNumber;
                            //        var sub = _userService.GetSubjectsForNotifications(user.UserId);
                            //        var subjects = sub.Where(x => x.TeacherSpecialityId == absenceDetail.SpecialityTypeId).FirstOrDefault();
                            //        if (absenceDetail.OnlySubjectSpecialist && subjects != null ? subjects.SubjectNotification : true &&
                            //            absenceDetail.OnlyCertified ? user.IsCertified == 1 : true)
                            //            CommunicationContainer.SMSProcessor.Process(message, (MailTemplateEnums)message.TemplateId);
                            //    }
                            //}
                        }

                        else if (user.RoleId == 4 && absenceDetail.AbsenceType != 2 && absenceDetail.AbsenceType != 5 && absenceDetail.SubstituteRequired)
                        {
                            message.TemplateId = 1;
                            var events         = _userService.GetSubstituteNotificationEvents(user.UserId);
                            var jobPostedEvent = events.Where(x => x.EventId == 2).First();
                            var grade          = _userService.GetGradeLevelsForNotification(user.UserId);
                            var isGradeEnabled = grade.Where(x => x.TeachingLevelId == absenceDetail.GradeId).FirstOrDefault();
                            var sub            = _userService.GetSubjectsForNotifications(user.UserId);
                            var subjects       = sub.Where(x => x.TeacherSpecialityId == absenceDetail.SpecialityTypeId).FirstOrDefault();
                            var cat            = _userService.GetSubstituteCategories(user.UserId);
                            var categories     = cat.Where(x => x.TypeId == absenceDetail.PositionId).FirstOrDefault();

                            if (user.IsSubscribedEmail && jobPostedEvent.EmailAlert && (isGradeEnabled != null ? isGradeEnabled.GradeNotification : true) &&
                                (subjects != null ? subjects.SubjectNotification : true) && (absenceDetail.OnlyCertified ? user.IsCertified == 1 : true) &&
                                (categories != null ? categories.IsNotificationSend : true))
                            {
                                if (absenceDetail.OrganizationId != "-1")
                                {
                                    var subSchools      = _userService.GetSubstitutePreferredSchools(user.UserId);
                                    var isSchoolEnabled = subSchools.Where(x => x.OrganizationId == absenceDetail.OrganizationId).First();
                                    if (isSchoolEnabled.IsEnabled)
                                    {
                                        await CommunicationContainer.EmailProcessor.ProcessAsync(message, (MailTemplateEnums)message.TemplateId);
                                    }
                                }
                                else
                                {
                                    await CommunicationContainer.EmailProcessor.ProcessAsync(message, (MailTemplateEnums)message.TemplateId);
                                }
                            }

                            if (user.IsSubscribedSMS && jobPostedEvent.TextAlert && (isGradeEnabled != null ? isGradeEnabled.GradeNotification : true) &&
                                (subjects != null ? subjects.SubjectNotification : true) && (absenceDetail.OnlyCertified ? user.IsCertified == 1 : true) &&
                                (categories != null ? categories.IsNotificationSend : true))
                            {
                                message.PhoneNumber = user.PhoneNumber;
                                if (absenceDetail.OrganizationId != "-1")
                                {
                                    var subSchools      = _userService.GetSubstitutePreferredSchools(user.UserId);
                                    var isSchoolEnabled = subSchools.Where(x => x.OrganizationId == absenceDetail.OrganizationId).First();
                                    if (isSchoolEnabled.IsEnabled)
                                    {
                                        message.PhoneNumber = user.PhoneNumber;
                                        CommunicationContainer.SMSProcessor.Process(message, (MailTemplateEnums)message.TemplateId);
                                    }
                                }
                                else
                                {
                                    CommunicationContainer.SMSProcessor.Process(message, (MailTemplateEnums)message.TemplateId);
                                }
                            }
                            //message.TemplateId = 1;
                            //if (user.IsSubscribedEmail)
                            //{
                            //    var events = _userService.GetSubstituteNotificationEvents(user.UserId);
                            //    var jobPostedEvent = events.Where(x => x.EventId == 2).First();
                            //    if (jobPostedEvent.EmailAlert)
                            //    {
                            //        var sub = _userService.GetSubjectsForNotifications(user.UserId);
                            //        var subjects = sub.Where(x => x.TeacherSpecialityId == absenceDetail.SpecialityTypeId).FirstOrDefault();
                            //        if (absenceDetail.OnlySubjectSpecialist && subjects != null ? subjects.SubjectNotification : true &&
                            //            absenceDetail.OnlyCertified ? user.IsCertified == 1 : true)
                            //            await CommunicationContainer.EmailProcessor.ProcessAsync(message, (MailTemplateEnums)message.TemplateId);
                            //    }

                            //}
                            //if (user.IsSubscribedSMS)
                            //{
                            //    message.PhoneNumber = user.PhoneNumber;
                            //    var sub = _userService.GetSubjectsForNotifications(user.UserId);
                            //    var subjects = sub.Where(x => x.TeacherSpecialityId == absenceDetail.SpecialityTypeId).FirstOrDefault();
                            //    if (absenceDetail.OnlySubjectSpecialist && subjects != null ? subjects.SubjectNotification : true &&
                            //        absenceDetail.OnlyCertified ? user.IsCertified == 1 : true)
                            //        CommunicationContainer.SMSProcessor.Process(message, (MailTemplateEnums)message.TemplateId);
                            //}
                        }
                        else if (user.RoleId == 3 && absenceDetail.AbsenceType != 2)
                        {
                            message.TemplateId = 10;
                            if (user.IsSubscribedEmail)
                            {
                                var events         = _userService.GetSubstituteNotificationEvents(user.UserId);
                                var jobPostedEvent = events.Where(x => x.EventId == 2).First();
                                if (jobPostedEvent.EmailAlert)
                                {
                                    await CommunicationContainer.EmailProcessor.ProcessAsync(message, (MailTemplateEnums)message.TemplateId);
                                }
                            }
                        }

                        else if (user.RoleId == 3 && absenceDetail.AbsenceType == 2)
                        {
                            message.TemplateId = 8;
                            if (user.IsSubscribedEmail)
                            {
                                var events         = _userService.GetSubstituteNotificationEvents(user.UserId);
                                var jobPostedEvent = events.Where(x => x.EventId == 2).First();
                                if (jobPostedEvent.EmailAlert)
                                {
                                    await CommunicationContainer.EmailProcessor.ProcessAsync(message, (MailTemplateEnums)message.TemplateId);
                                }
                            }
                        }

                        //For Admins
                        else if ((user.RoleId == 1 || user.RoleId == 2) && absenceDetail.AbsenceType == 2)
                        {
                            message.TemplateId = 8;
                            if (user.IsSubscribedEmail)
                            {
                                var events         = _userService.GetSubstituteNotificationEvents(user.UserId);
                                var jobPostedEvent = events.Where(x => x.EventId == 2).First();
                                if (jobPostedEvent.EmailAlert)
                                {
                                    await CommunicationContainer.EmailProcessor.ProcessAsync(message, (MailTemplateEnums)message.TemplateId);
                                }
                            }
                        }

                        else if ((user.RoleId == 1 || user.RoleId == 2) && absenceDetail.AbsenceType != 2)
                        {
                            message.TemplateId = 2;
                            if (user.IsSubscribedEmail)
                            {
                                var events         = _userService.GetSubstituteNotificationEvents(user.UserId);
                                var jobPostedEvent = events.Where(x => x.EventId == 2).First();
                                if (jobPostedEvent.EmailAlert)
                                {
                                    await CommunicationContainer.EmailProcessor.ProcessAsync(message, (MailTemplateEnums)message.TemplateId);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
        }