Beispiel #1
0
        /// <summary>
        /// Method for sending bell notification when a student's leave is approved - RS
        /// </summary>
        /// <param name="leaveApprovedByUser"></param>
        /// <param name="studentLeave"></param>
        /// <param name="instituteId"></param>
        /// <returns></returns>
        public async Task SendBellNotificationsForStudentLeaveApproveRejectAsync(ApplicationUser leaveApprovedByUser, StudentLeave studentLeave, int instituteId)
        {
            StaffBasicPersonalInformation staffUser = await _iMSDbContext.StaffBasicPersonalInformation
                                                      .Include(x => x.User)
                                                      .FirstOrDefaultAsync(x => x.UserId == leaveApprovedByUser.Id);

            LeaveType leaveType = await _iMSDbContext.LeaveTypes.FirstAsync(x => x.Id == studentLeave.LeaveTypeId);

            StudentBasicInformation leaveForStudent = (await _iMSDbContext.StudentBasicInformation
                                                       .Include(x => x.User)
                                                       .Include(x => x.CurrentClass)
                                                       .ThenInclude(x => x.ClassTeacher)
                                                       .ThenInclude(x => x.User)
                                                       .Include(x => x.Institute)
                                                       .FirstAsync(x => x.Id == studentLeave.StudentId));

            NotificationAc notificationAc = new NotificationAc
            {
                NotificationMessage          = leaveType.Name,
                NotificationTo               = null,
                NotificationUserMappingsList = new List <NotificationUserMappingAc>()
            };

            // For Student
            notificationAc.NotificationDetails = string.Format("Your {0} has been updated", leaveType.Name);
            notificationAc.NotificationUserMappingsList.Add(new NotificationUserMappingAc
            {
                UserId = leaveForStudent.UserId
            });

            await _notificationManagementRepository.AddNotificationAsync(notificationAc, instituteId, leaveApprovedByUser);

            notificationAc.NotificationUserMappingsList = new List <NotificationUserMappingAc>();

            // For the leave approver
            notificationAc.NotificationDetails = string.Format("You have updated the {0} request of {1} of class {2}",
                                                               leaveType.Name, leaveForStudent.FirstName, leaveForStudent.CurrentClass.Name);
            notificationAc.NotificationUserMappingsList.Add(new NotificationUserMappingAc
            {
                UserId = leaveApprovedByUser.Id
            });

            await _notificationManagementRepository.AddNotificationAsync(notificationAc, instituteId, leaveApprovedByUser);

            notificationAc.NotificationUserMappingsList = new List <NotificationUserMappingAc>();

            // Approved by the admin (For Class Teacher)
            if (staffUser == null && leaveForStudent.CurrentClass.ClassTeacherId.HasValue)
            {
                notificationAc.NotificationDetails = string.Format("The {0} request of {1} of class {2} has been updated",
                                                                   leaveType.Name, leaveForStudent.FirstName, leaveForStudent.CurrentClass.Name);
                notificationAc.NotificationUserMappingsList.Add(new NotificationUserMappingAc
                {
                    UserId = leaveForStudent.CurrentClass.ClassTeacher?.UserId
                });

                await _notificationManagementRepository.AddNotificationAsync(notificationAc, instituteId, leaveApprovedByUser);

                notificationAc.NotificationUserMappingsList = new List <NotificationUserMappingAc>();
            }
            // Approved by the staff (For admin)
            else if (staffUser != null)
            {
                notificationAc.NotificationDetails = string.Format("The {0} request of {1} of class {2} has been updated by {3}",
                                                                   leaveType.Name, leaveForStudent.FirstName, leaveForStudent.CurrentClass.Name, staffUser.FirstName);
                notificationAc.NotificationUserMappingsList.Add(new NotificationUserMappingAc
                {
                    UserId = leaveForStudent.Institute.AdminId
                });

                await _notificationManagementRepository.AddNotificationAsync(notificationAc, instituteId, leaveApprovedByUser);

                notificationAc.NotificationUserMappingsList = new List <NotificationUserMappingAc>();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Method to apply student leave - SS
        /// </summary>
        /// <param name="addStudentLeave">leave detail</param>
        /// <param name="instituteId">institute id</param>
        /// <returns>response</returns>
        public async Task <StudentLeaveResponse> AddStudentLeaveAsync(AddStudentLeaveAc addStudentLeave, int instituteId, ApplicationUser currentUser)
        {
            if (string.IsNullOrEmpty(addStudentLeave.Reason.Trim()))
            {
                return new StudentLeaveResponse()
                       {
                           HasError = true, Message = "Leave reason can't be empty", ErrorType = StudentLeaveResponseType.Reason
                       }
            }
            ;
            else
            {
                if (!await _iMSDbContext.StudentBasicInformation.AnyAsync(x => x.Id == addStudentLeave.StudentId && x.InstituteId == instituteId))
                {
                    return new StudentLeaveResponse()
                           {
                               HasError = true, Message = "Student not found", ErrorType = StudentLeaveResponseType.StudentId
                           }
                }
                ;
                else
                {
                    if (!await _iMSDbContext.LeaveTypes.AnyAsync(x => x.Id == addStudentLeave.LeaveTypeId && x.InstituteId == instituteId))
                    {
                        return new StudentLeaveResponse()
                               {
                                   HasError = true, Message = "Leave type not found", ErrorType = StudentLeaveResponseType.LeaveTypeId
                               }
                    }
                    ;
                    else
                    {
                        if (!await _iMSDbContext.LeaveStatuses.AnyAsync(x => x.Id == addStudentLeave.StatusId && x.InstituteId == instituteId))
                        {
                            return new StudentLeaveResponse()
                                   {
                                       HasError = true, Message = "Status not found", ErrorType = StudentLeaveResponseType.StatusId
                                   }
                        }
                        ;
                        else
                        {
                            if (!await _iMSDbContext.StaffBasicPersonalInformation.AnyAsync(x => x.Id == addStudentLeave.ApprovedById && x.InstituteId == instituteId))
                            {
                                return new StudentLeaveResponse()
                                       {
                                           HasError = true, Message = "Staff not found", ErrorType = StudentLeaveResponseType.ApprovedById
                                       }
                            }
                            ;
                            else
                            {
                                var currentAcademicYear = await _iMSDbContext.InstituteAcademicYears.FirstAsync(x => x.IsActive && x.InstituteId == instituteId);

                                var leave = new StudentLeave()
                                {
                                    ApprovedById   = addStudentLeave.ApprovedById,
                                    CreatedOn      = DateTime.UtcNow,
                                    EndDate        = addStudentLeave.EndDate,
                                    FromDate       = addStudentLeave.FromDate,
                                    LeaveTypeId    = addStudentLeave.LeaveTypeId,
                                    StatusId       = addStudentLeave.StatusId,
                                    Reason         = addStudentLeave.Reason,
                                    StudentId      = addStudentLeave.StudentId,
                                    AcademicYearId = currentAcademicYear.Id
                                };
                                _iMSDbContext.StudentLeaves.Add(leave);
                                await _iMSDbContext.SaveChangesAsync();

                                #region Send Mail/Message

                                leave = await _iMSDbContext.StudentLeaves.Include(s => s.Student).Include(s => s.LeaveType)
                                        .Include(s => s.LeaveStatus).Include(s => s.ApprovedBy).FirstAsync(x => x.Id == leave.Id);

                                await _templateManagementRepository.TriggerMailOrMessageAsync(instituteId, TemplateTypeEnum.StudentLeaveAdd,
                                                                                              TemplateFormatEnum.Email, leave);

                                await _templateManagementRepository.TriggerMailOrMessageAsync(instituteId, TemplateTypeEnum.StudentLeaveAdd,
                                                                                              TemplateFormatEnum.Sms, leave);

                                #endregion

                                await SendBellNotificationsForStudentsLeavesAsync(currentUser, addStudentLeave.LeaveTypeId, addStudentLeave.StudentId, instituteId);

                                return(new StudentLeaveResponse()
                                {
                                    HasError = false, Message = "Leave applied succesfully"
                                });
                            }
                        }
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Method for adding event report details
        /// </summary>
        /// <param name="template"></param>
        /// <param name="data"></param>
        /// <param name="instituteId"></param>
        /// <returns></returns>
        private async Task AddEventReportDetail(Template template, object data, int instituteId)
        {
            switch (template.TemplateType)
            {
            case TemplateTypeEnum.ChangePassword:
            {
                ApplicationUser user = data as ApplicationUser;
                await _eventManagementRepository.AddEventReportInfoAsync(instituteId, string.Format("{0} updated password", user.Name),
                                                                         EnumHelperService.GetDescription(template.TemplateType), user.Name, template.TemplateFormat);
            }
            break;

            case TemplateTypeEnum.FeePaymentAdd:
            {
                FeeReceipt feeReceipt = data as FeeReceipt;
                await _eventManagementRepository.AddEventReportInfoAsync(instituteId, "Fee payment added", EnumHelperService.GetDescription(template.TemplateType),
                                                                         feeReceipt.Student.FirstName, template.TemplateFormat);
            }
            break;

            case TemplateTypeEnum.FeePaymentReminder:
            {
                FeeReceipt feeReceipt = data as FeeReceipt;
                await _eventManagementRepository.AddEventReportInfoAsync(instituteId, "Fee payment reminder sent", EnumHelperService.GetDescription(template.TemplateType),
                                                                         feeReceipt.Student.FirstName, template.TemplateFormat);
            }
            break;

            case TemplateTypeEnum.ForgotPassword:
            {
                ApplicationUser user = data as ApplicationUser;
                await _eventManagementRepository.AddEventReportInfoAsync(instituteId, string.Format("{0} updated password", user.Name), EnumHelperService.GetDescription(template.TemplateType),
                                                                         user.Name, template.TemplateFormat);
            }
            break;

            case TemplateTypeEnum.StaffAdd:
            {
                StaffBasicPersonalInformation staff = data as StaffBasicPersonalInformation;
                await _eventManagementRepository.AddEventReportInfoAsync(instituteId, string.Format("New staff ({0}) added", staff.FirstName),
                                                                         EnumHelperService.GetDescription(template.TemplateType), staff.FirstName, template.TemplateFormat);
            }
            break;

            case TemplateTypeEnum.StaffDelete:
            {
                StaffBasicPersonalInformation staff = data as StaffBasicPersonalInformation;
                await _eventManagementRepository.AddEventReportInfoAsync(instituteId, string.Format("Staff ({0}) deleted", staff.FirstName),
                                                                         EnumHelperService.GetDescription(template.TemplateType), staff.FirstName, template.TemplateFormat);
            }
            break;

            case TemplateTypeEnum.StaffEdit:
            {
                StaffBasicPersonalInformation staff = data as StaffBasicPersonalInformation;
                await _eventManagementRepository.AddEventReportInfoAsync(instituteId, string.Format("Staff ({0}) details updated", staff.FirstName),
                                                                         EnumHelperService.GetDescription(template.TemplateType), staff.FirstName, template.TemplateFormat);
            }
            break;

            case TemplateTypeEnum.StaffLeaveAdd:
            {
                StaffLeave leave = data as StaffLeave;
                await _eventManagementRepository.AddEventReportInfoAsync(instituteId, string.Format("Leave added for the staff {0}", leave.Staff.FirstName),
                                                                         EnumHelperService.GetDescription(template.TemplateType), leave.Staff.FirstName, template.TemplateFormat);
            }
            break;

            case TemplateTypeEnum.StaffLeaveApproveReject:
            {
                StaffLeave leave = data as StaffLeave;
                await _eventManagementRepository.AddEventReportInfoAsync(instituteId, string.Format("Leave updated for the staff {0}", leave.Staff.FirstName),
                                                                         EnumHelperService.GetDescription(template.TemplateType), leave.Staff.FirstName, template.TemplateFormat);
            }
            break;

            case TemplateTypeEnum.StaffLeaveEdit:
            {
                StaffLeave leave = data as StaffLeave;
                await _eventManagementRepository.AddEventReportInfoAsync(instituteId, string.Format("Leave updated for the staff {0}", leave.Staff.FirstName),
                                                                         EnumHelperService.GetDescription(template.TemplateType), leave.Staff.FirstName, template.TemplateFormat);
            }
            break;

            case TemplateTypeEnum.StudentAdd:
            {
                StudentBasicInformation student = data as StudentBasicInformation;
                await _eventManagementRepository.AddEventReportInfoAsync(instituteId, string.Format("New student ({0}) added", student.FirstName),
                                                                         EnumHelperService.GetDescription(template.TemplateType), student.FirstName, template.TemplateFormat);
            }
            break;

            case TemplateTypeEnum.StudentDelete:
            {
                StudentBasicInformation student = data as StudentBasicInformation;
                await _eventManagementRepository.AddEventReportInfoAsync(instituteId, string.Format("Student ({0}) deleted", student.FirstName),
                                                                         EnumHelperService.GetDescription(template.TemplateType), student.FirstName, template.TemplateFormat);
            }
            break;

            case TemplateTypeEnum.StudentEdit:
            {
                StudentBasicInformation student = data as StudentBasicInformation;
                await _eventManagementRepository.AddEventReportInfoAsync(instituteId, string.Format("Student ({0}) details updated", student.FirstName),
                                                                         EnumHelperService.GetDescription(template.TemplateType), student.FirstName, template.TemplateFormat);
            }
            break;

            case TemplateTypeEnum.StudentLeaveAdd:
            {
                StudentLeave leave = data as StudentLeave;
                await _eventManagementRepository.AddEventReportInfoAsync(instituteId, string.Format("Leave added for the student {0}", leave.Student.FirstName),
                                                                         EnumHelperService.GetDescription(template.TemplateType), leave.Student.FirstName, template.TemplateFormat);
            }
            break;

            case TemplateTypeEnum.StudentLeaveApproveReject:
            {
                StudentLeave leave = data as StudentLeave;
                await _eventManagementRepository.AddEventReportInfoAsync(instituteId, string.Format("Leave updated for the student {0}", leave.Student.FirstName),
                                                                         EnumHelperService.GetDescription(template.TemplateType), leave.Student.FirstName, template.TemplateFormat);
            }
            break;

            case TemplateTypeEnum.StudentLeaveEdit:
            {
                StudentLeave leave = data as StudentLeave;
                await _eventManagementRepository.AddEventReportInfoAsync(instituteId, string.Format("Leave updated for the student {0}", leave.Student.FirstName),
                                                                         EnumHelperService.GetDescription(template.TemplateType), leave.Student.FirstName, template.TemplateFormat);
            }
            break;

            case TemplateTypeEnum.TimeTable:
            {
                TimeTable timeTable = data as TimeTable;
                await _eventManagementRepository.AddEventReportInfoAsync(instituteId, string.Format("Timetable added for class {0}", timeTable.Class.Name),
                                                                         EnumHelperService.GetDescription(template.TemplateType), string.Empty, template.TemplateFormat);
            }
            break;
            }
        }