public OrganizationModel InsertSchool([FromBody] OrganizationModel model)
 {
     try
     {
         var school = _service.InsertSchool(model);
         // Audit Log
         var audit = new AuditLog
         {
             UserId         = CurrentUser.Id,
             EntityId       = model.SchoolId.ToString(),
             EntityType     = AuditLogs.EntityType.School,
             ActionType     = AuditLogs.ActionType.CreatedSchool,
             PostValue      = Serializer.Serialize(model),
             DistrictId     = CurrentUser.DistrictId,
             OrganizationId = CurrentUser.OrganizationId == "-1" ? null : CurrentUser.OrganizationId
         };
         _audit.InsertAuditLog(audit);
         return(school);
     }
     catch (Exception ex)
     {
     }
     finally
     {
     }
     return(null);
 }
 public IActionResult Post([FromBody] UserAvailability model)
 {
     try
     {
         model.UserId    = base.CurrentUser.Id;
         model.CreatedBy = base.CurrentUser.Id;
         var result = _service.InsertAvailability(model);
         if (result != "accepted" && result != "unavailable")
         {
             // Audit Log
             var audit = new AuditLog
             {
                 UserId         = CurrentUser.Id,
                 EntityId       = result.ToString(),
                 EntityType     = AuditLogs.EntityType.Unavailability,
                 ActionType     = AuditLogs.ActionType.CreatedUnavailability,
                 PostValue      = Serializer.Serialize(model),
                 DistrictId     = CurrentUser.DistrictId,
                 OrganizationId = CurrentUser.OrganizationId == "-1" ? null : CurrentUser.OrganizationId
             };
             _audit.InsertAuditLog(audit);
             return(Json("success"));
         }
         return(Json(result));
     }
     catch (Exception ex)
     {
     }
     finally
     {
     }
     return(null);
 }
Esempio n. 3
0
 public IActionResult InsertAbsencesLogView([FromBody] AuditLogFilter model)
 {
     try
     {
         model.LoginUserId    = base.CurrentUser.Id;
         model.DistrictId     = base.CurrentUser.DistrictId;
         model.OrganizationId = base.CurrentUser.OrganizationId == "-1" ? null : base.CurrentUser.OrganizationId;
         // Audit Log
         var audit = new AuditLog
         {
             UserId         = CurrentUser.Id,
             EntityId       = model.EntityId.ToString(),
             EntityType     = AuditLogs.EntityType.Absence,
             ActionType     = AuditLogs.ActionType.Viewed,
             DistrictId     = CurrentUser.DistrictId,
             OrganizationId = CurrentUser.OrganizationId == "-1" ? null : CurrentUser.OrganizationId
         };
         _audit.InsertAuditLog(audit);
         return(Ok());
     }
     catch (Exception ex)
     {
     }
     finally
     {
     }
     return(null);
 }
 public IActionResult InsertAnnouncement([FromBody] Announcements model)
 {
     try
     {
         var AnnouncementId = _service.InsertAnnouncement(model);
         // Audit Log
         var audit = new AuditLog
         {
             UserId         = CurrentUser.Id,
             EntityId       = model.AnnouncementId.ToString(),
             EntityType     = AuditLogs.EntityType.Announcement,
             ActionType     = AuditLogs.ActionType.CreatedAnnouncement,
             PostValue      = Serializer.Serialize(model),
             DistrictId     = CurrentUser.DistrictId,
             OrganizationId = CurrentUser.OrganizationId == "-1" ? null : CurrentUser.OrganizationId
         };
         _audit.InsertAuditLog(audit);
         return(Json(AnnouncementId));
     }
     catch (Exception ex)
     {
     }
     finally
     {
     }
     return(null);
 }
 public LeaveRequestModel UpdateLeaveRequestStatus([FromBody] LeaveRequestModel model)
 {
     try
     {
         model.ApprovedBy = base.CurrentUser.Id;
         var leaveRequests = _service.UpdateLeaveRequestStatus(model);
         // Audit Log
         if (model.IsApproved == true)
         {
             var audit = new AuditLog
             {
                 UserId         = CurrentUser.Id,
                 EntityId       = model.ConfirmationNumber.ToString(),
                 EntityType     = AuditLogs.EntityType.Absence,
                 ActionType     = AuditLogs.ActionType.Approved,
                 DistrictId     = CurrentUser.DistrictId,
                 OrganizationId = CurrentUser.OrganizationId == "-1" ? null : CurrentUser.OrganizationId
             };
             _audit.InsertAuditLog(audit);
         }
         if (model.IsDeniend == true)
         {
             var audit = new AuditLog
             {
                 UserId         = CurrentUser.Id,
                 EntityId       = model.ConfirmationNumber.ToString(),
                 EntityType     = AuditLogs.EntityType.Absence,
                 ActionType     = AuditLogs.ActionType.Denied,
                 DistrictId     = CurrentUser.DistrictId,
                 OrganizationId = CurrentUser.OrganizationId == "-1" ? null : CurrentUser.OrganizationId
             };
             _audit.InsertAuditLog(audit);
         }
         if (model.IsArchived == true)
         {
             var audit = new AuditLog
             {
                 UserId         = CurrentUser.Id,
                 EntityId       = model.ConfirmationNumber.ToString(),
                 EntityType     = AuditLogs.EntityType.Absence,
                 ActionType     = AuditLogs.ActionType.Archived,
                 DistrictId     = CurrentUser.DistrictId,
                 OrganizationId = CurrentUser.OrganizationId == "-1" ? null : CurrentUser.OrganizationId
             };
             _audit.InsertAuditLog(audit);
         }
         //Notification notification = new Notification(_userService, _absenceService);
         Task.Run(() => SendNotificationsOnJobApprovedOrDenied(model));
         return(leaveRequests);
     }
     catch (Exception ex)
     {
     }
     finally
     {
     }
     return(null);
 }
 public IActionResult InsertDistrict([FromBody] DistrictModel model)
 {
     try
     {
         DistrictValidator validator = new DistrictValidator();
         ValidationResult  result    = validator.Validate(model);
         if (result.IsValid)
         {
             var userModel = _service.InsertDistrict(model);
             // Audit Log
             var audit = new AuditLog
             {
                 UserId         = CurrentUser.Id,
                 EntityId       = model.DistrictId.ToString(),
                 EntityType     = AuditLogs.EntityType.District,
                 ActionType     = AuditLogs.ActionType.CreatedDistrict,
                 PostValue      = Serializer.Serialize(model),
                 DistrictId     = CurrentUser.DistrictId,
                 OrganizationId = CurrentUser.OrganizationId == "-1" ? null : CurrentUser.OrganizationId
             };
             _audit.InsertAuditLog(audit);
         }
         else
         {
             return(BadRequest("Fill All fields"));
         }
         return(Json("successfull"));
     }
     catch (Exception ex)
     {
     }
     finally
     {
     }
     return(null);
 }
Esempio n. 7
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);
        }
        public IEnumerable <FileManager> AddFiles([FromBody] FileManager fileManager)
        {
            try
            {
                fileManager.DistrictId     = base.CurrentUser.DistrictId;
                fileManager.OrganizationId = base.CurrentUser.OrganizationId == "-1" ? null : base.CurrentUser.OrganizationId;
                fileManager.UserId         = base.CurrentUser.Id;
                var Files = _service.AddFiles(fileManager);

                // Audit Log
                if (fileManager.FileType == "2")
                {
                    // Audit Log
                    var audit = new AuditLog
                    {
                        UserId         = CurrentUser.Id,
                        EntityId       = fileManager.UserId.ToString(),
                        EntityType     = AuditLogs.EntityType.User,
                        ActionType     = AuditLogs.ActionType.TGuideForAdmin,
                        PostValue      = Serializer.Serialize(fileManager),
                        DistrictId     = CurrentUser.DistrictId,
                        OrganizationId = CurrentUser.OrganizationId == "-1" ? null : CurrentUser.OrganizationId
                    };
                    _audit.InsertAuditLog(audit);
                }
                else if (fileManager.FileType == "3")
                {
                    // Audit Log
                    var audit = new AuditLog
                    {
                        UserId         = CurrentUser.Id,
                        EntityId       = fileManager.UserId.ToString(),
                        EntityType     = AuditLogs.EntityType.User,
                        ActionType     = AuditLogs.ActionType.TGuideForStaff,
                        PostValue      = Serializer.Serialize(fileManager),
                        DistrictId     = CurrentUser.DistrictId,
                        OrganizationId = CurrentUser.OrganizationId == "-1" ? null : CurrentUser.OrganizationId
                    };
                    _audit.InsertAuditLog(audit);
                }
                else if (fileManager.FileType == "4")
                {
                    // Audit Log
                    var audit = new AuditLog
                    {
                        UserId         = CurrentUser.Id,
                        EntityId       = fileManager.UserId.ToString(),
                        EntityType     = AuditLogs.EntityType.User,
                        ActionType     = AuditLogs.ActionType.TGuideForSub,
                        PostValue      = Serializer.Serialize(fileManager),
                        DistrictId     = CurrentUser.DistrictId,
                        OrganizationId = CurrentUser.OrganizationId == "-1" ? null : CurrentUser.OrganizationId
                    };
                    _audit.InsertAuditLog(audit);
                }
                else
                {
                    // Audit Log
                    var audit = new AuditLog
                    {
                        UserId         = CurrentUser.Id,
                        EntityId       = fileManager.UserId.ToString(),
                        EntityType     = AuditLogs.EntityType.User,
                        ActionType     = AuditLogs.ActionType.SubstituteFile,
                        PostValue      = Serializer.Serialize(fileManager),
                        DistrictId     = CurrentUser.DistrictId,
                        OrganizationId = CurrentUser.OrganizationId == "-1" ? null : CurrentUser.OrganizationId
                    };
                    _audit.InsertAuditLog(audit);
                }
                return(Files);
            }
            catch (Exception ex)
            {
            }
            finally
            {
            }
            return(null);
        }
Esempio n. 9
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));
        }
        public IActionResult Login([FromBody] UserLogin user)
        {
            try
            {
                var UserInfo = _service.GetUserByCredentials(user.UserName, user.Password);
                if (user == null)
                {
                    return(BadRequest("Invalid client request"));
                }

                if (UserInfo != null)
                {
                    if (!UserInfo.IsCertified)
                    {
                        return(BadRequest("NotCertified"));
                    }
                    else if (!UserInfo.IsActive)
                    {
                        return(BadRequest("notactive"));
                    }
                    else
                    {
                        var userDetail  = _userService.GetUserDetail(UserInfo.UserId);
                        var secretKey   = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("P@$sw0rd123Ki@Keysec"));
                        var credentials = new SigningCredentials(secretKey, SecurityAlgorithms.HmacSha256);

                        var tokeOptions = new JwtSecurityToken(
                            //issuer: "http://localhost:56412",
                            //audience: "http://localhost:56412",
                            claims: new List <Claim> {
                            new Claim("UserId", UserInfo.UserId.ToString()),
                            new Claim("districtId", userDetail.DistrictId.ToString()),
                            new Claim("organizationId", !string.IsNullOrEmpty(userDetail.OrganizationId)  ? userDetail.OrganizationId.ToString(): "-1")
                        },
                            expires: DateTime.Now.AddMinutes(20),
                            signingCredentials: credentials
                            );
                        // Audit Log
                        var audit = new AuditLog
                        {
                            UserId         = UserInfo.UserId,
                            EntityType     = AuditLogs.EntityType.User,
                            ActionType     = AuditLogs.ActionType.LoggedIn,
                            DistrictId     = userDetail.DistrictId,
                            OrganizationId = !string.IsNullOrEmpty(userDetail.OrganizationId) ? userDetail.OrganizationId.ToString() : "null"
                        };
                        _audit.InsertAuditLog(audit);

                        var token = new JwtSecurityTokenHandler().WriteToken(tokeOptions);
                        return(Ok(new { Token = token }));
                    }
                }
                else
                {
                    return(Unauthorized());
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
            }
            return(null);
        }