public async Task <IActionResult> GetActivitiesForParticularStaffAsync(int staffId) { ApplicationUser user = await GetLoggedInUserAsync(); StaffBasicPersonalInformation staff = await _iMSDbContext.StaffBasicPersonalInformation.FirstOrDefaultAsync(x => x.Id == staffId); if (staff == null) { return(NotFound(new ApiServiceResponse() { Status = -100, Message = "Staff not found" })); } else { if (await _iMSDbContext.UserInstituteMappings.AnyAsync(x => x.InstituteId == staff.InstituteId && x.UserId == user.Id)) { List <StaffActivity> staffActivityList = await _staffActivityManagementRepository.GetActivitiesForStaffAsync(staff.InstituteId.Value, staffId); return(Ok(new ApiServiceResponse { Status = 200, Message = "Success", ResultObj = staffActivityList })); } else { return(BadRequest(new ApiServiceResponse() { Status = -100, Message = "Un-authorized to get detail, you doesn't belong to this institute" })); } } }
public async Task <IActionResult> GetTimeTableDetailsForStaffAsync([FromBody] GetTimeTableAc getTimeTableAc) { if (!getTimeTableAc.StaffId.HasValue || getTimeTableAc.StaffId.Value == 0) { return(BadRequest(new ApiServiceResponse() { Status = -100, Message = "Staff Id can't be empty" })); } else { StaffBasicPersonalInformation staff = await _iMSDbContext.StaffBasicPersonalInformation.FirstOrDefaultAsync(x => x.Id == getTimeTableAc.StaffId.Value); if (staff == null) { return(NotFound(new ApiServiceResponse() { Status = -100, Message = "Staff not found" })); } AddTimeTableAc timeTableDetails = await _timeTableManagementRepository.GetTimeTableForStaffAsync(getTimeTableAc.ClassId, getTimeTableAc.SectionId, getTimeTableAc.StaffId.Value, getTimeTableAc.AcademicYearId, getTimeTableAc.InstituteId); return(Ok(new ApiServiceResponse { Status = 200, Message = "Success", ResultObj = timeTableDetails })); } }
/// <summary> /// Method for sending bell botification for staffs' leaves - RS /// </summary> /// <param name="currentUser"></param> /// <param name="leaveTypeId"></param> /// <param name="leaveForStaffId"></param> /// <param name="instituteId"></param> /// <returns></returns> private async Task SendBellNotificationsForStaffssLeavesAsync(ApplicationUser currentUser, int leaveTypeId, int leaveForStaffId, int instituteId) { StaffBasicPersonalInformation staffUser = await _iMSDbContext.StaffBasicPersonalInformation .Include(x => x.User) .Include(x => x.Institute) .FirstOrDefaultAsync(x => x.UserId == currentUser.Id); LeaveType leaveType = await _iMSDbContext.LeaveTypes.FirstAsync(x => x.Id == leaveTypeId); StaffBasicPersonalInformation leaveForStaff = (await _iMSDbContext.StaffBasicPersonalInformation .Include(x => x.User) .Include(x => x.Institute) .FirstAsync(x => x.Id == leaveForStaffId)); NotificationAc notificationAc = new NotificationAc { NotificationMessage = leaveType.Name, NotificationTo = null, NotificationUserMappingsList = new List <NotificationUserMappingAc>() }; // Created by the admin if (staffUser == null) { // For Staff notificationAc.NotificationDetails = string.Format("Your {0} has been applied successfully", leaveType.Name); notificationAc.NotificationUserMappingsList.Add(new NotificationUserMappingAc { UserId = leaveForStaff.UserId }); await _notificationManagementRepository.AddNotificationAsync(notificationAc, instituteId, currentUser); notificationAc.NotificationUserMappingsList = new List <NotificationUserMappingAc>(); } // Created by the Staff else { // For Staff notificationAc.NotificationDetails = string.Format("Your {0} has been applied successfully", leaveType.Name); notificationAc.NotificationUserMappingsList.Add(new NotificationUserMappingAc { UserId = staffUser.UserId }); await _notificationManagementRepository.AddNotificationAsync(notificationAc, instituteId, currentUser); notificationAc.NotificationUserMappingsList = new List <NotificationUserMappingAc>(); // For Admin notificationAc.NotificationDetails = string.Format("New {0} request from {1}", leaveType.Name, staffUser.FirstName); notificationAc.NotificationUserMappingsList.Add(new NotificationUserMappingAc { UserId = staffUser.Institute.AdminId }); await _notificationManagementRepository.AddNotificationAsync(notificationAc, instituteId, currentUser); } }
/// <summary> /// Method for setting bell notification on creation of homeworks /// </summary> /// <param name="homeWork"></param> /// <param name="currentUser"></param> /// <param name="instituteId"></param> /// <returns></returns> private async Task SendBellNotificationOnHomewordCreation(AddHomeworkManagementAc homeWork, ApplicationUser currentUser, int instituteId) { StaffBasicPersonalInformation homeWorkCreatedByStaff = await _iMSDbContext.StaffBasicPersonalInformation .FirstOrDefaultAsync(x => x.UserId == currentUser.Id); List <StudentBasicInformation> recipientStudentsList = await _iMSDbContext.StudentBasicInformation .Where(x => x.CurrentClassId == homeWork.ClassId && x.SectionId == homeWork.SectionId && x.IsActive && !x.IsArchived) .ToListAsync(); NotificationAc notificationAc = new NotificationAc { NotificationMessage = "Homework", NotificationTo = null, NotificationUserMappingsList = new List <NotificationUserMappingAc>() }; // For students notificationAc.NotificationDetails = string.Format("Homework: Complete assignment dated {0}", homeWork.HomeworkDate.ToString("dd-MM-yyyy")); foreach (StudentBasicInformation recipientStudent in recipientStudentsList) { notificationAc.NotificationUserMappingsList.Add(new NotificationUserMappingAc { UserId = recipientStudent.UserId }); } await _notificationManagementRepository.AddNotificationAsync(notificationAc, instituteId, currentUser); notificationAc.NotificationUserMappingsList = new List <NotificationUserMappingAc>(); if (homeWorkCreatedByStaff != null) { InstituteClass instituteClass = await _iMSDbContext.InstituteClasses .Include(x => x.Institute) .FirstAsync(x => x.Id == homeWork.ClassId); // To self notificationAc.NotificationDetails = string.Format("You have added homework for {0}", instituteClass.Name); notificationAc.NotificationUserMappingsList.Add(new NotificationUserMappingAc { UserId = homeWorkCreatedByStaff.UserId }); await _notificationManagementRepository.AddNotificationAsync(notificationAc, instituteId, currentUser); notificationAc.NotificationUserMappingsList = new List <NotificationUserMappingAc>(); // To the admin notificationAc.NotificationDetails = string.Format("{0} has added homework for {1}", homeWorkCreatedByStaff.FirstName, instituteClass.Name); notificationAc.NotificationUserMappingsList.Add(new NotificationUserMappingAc { UserId = instituteClass.Institute.AdminId }); await _notificationManagementRepository.AddNotificationAsync(notificationAc, instituteId, currentUser); notificationAc.NotificationUserMappingsList = new List <NotificationUserMappingAc>(); } }
/// <summary> /// Method for sending bell notification when a staff's leave is approved - RS /// </summary> /// <param name="leaveApprovedByUser"></param> /// <param name="staffLeave"></param> /// <param name="instituteId"></param> /// <returns></returns> public async Task SendBellNotificationForStaffLeaveApproveRejectAsync(ApplicationUser leaveApprovedByUser, StaffLeave staffLeave, int instituteId) { LeaveType leaveType = await _iMSDbContext.LeaveTypes.FirstAsync(x => x.Id == staffLeave.LeaveTypeId); StaffBasicPersonalInformation leaveForStaff = (await _iMSDbContext.StaffBasicPersonalInformation .Include(x => x.User) .Include(x => x.Institute) .FirstAsync(x => x.Id == staffLeave.StaffId)); NotificationAc notificationAc = new NotificationAc { NotificationMessage = leaveType.Name, NotificationTo = null, NotificationUserMappingsList = new List <NotificationUserMappingAc>() }; // For Staff notificationAc.NotificationDetails = string.Format("Your {0} has been updated", leaveType.Name); notificationAc.NotificationUserMappingsList.Add(new NotificationUserMappingAc { UserId = leaveForStaff.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}", leaveType.Name, leaveForStaff.FirstName); notificationAc.NotificationUserMappingsList.Add(new NotificationUserMappingAc { UserId = leaveApprovedByUser.Id }); await _notificationManagementRepository.AddNotificationAsync(notificationAc, instituteId, leaveApprovedByUser); }
/// <summary> /// Method for fetching the dashboard data of a logged in, non-admin user - RS /// </summary> /// <param name="currentUser"></param> /// <returns></returns> public async Task <UserDashboardAc> GetLoggedInUserDashboard(ApplicationUser currentUser, int academicYearId) { int currentUserInstituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(currentUser.Id, true); UserDashboardAc userDashboardAc = new UserDashboardAc(); StudentBasicInformation studentUser = await _iMSDbContext.StudentBasicInformation .Include(x => x.CurrentClass) .Include(x => x.SectionMap) .Include(x => x.Nationality) .Include(x => x.Religion) .FirstOrDefaultAsync(x => x.InstituteId == currentUserInstituteId && x.UserId.Equals(currentUser.Id)); StaffBasicPersonalInformation staffUser = await _iMSDbContext.StaffBasicPersonalInformation .Include(x => x.Nationality) .Include(x => x.Religion) .FirstOrDefaultAsync(x => x.InstituteId == currentUserInstituteId && x.UserId.Equals(currentUser.Id)); List <StudentBasicInformation> totalStudents = await _iMSDbContext.StudentBasicInformation .Where(x => x.InstituteId == currentUserInstituteId && x.IsActive).ToListAsync(); if (studentUser != null) { userDashboardAc.Name = studentUser.FirstName + ' ' + studentUser.MiddleName + ' ' + studentUser.LastName; userDashboardAc.Nationality = studentUser.Nationality?.Name; userDashboardAc.Institute = (await _iMSDbContext.Institutes.FirstAsync(x => x.Id == currentUserInstituteId)).Name; userDashboardAc.PhoneNumber = studentUser.MobileNumber; userDashboardAc.Email = studentUser.FamilyRelationEmail; userDashboardAc.Religion = studentUser.Religion?.Name; userDashboardAc.Class = studentUser.CurrentClass?.Name; userDashboardAc.Section = studentUser.SectionMap?.Name; userDashboardAc.PersonalImage = studentUser.PersonalImage; userDashboardAc.RollNumber = studentUser.RollNumber; userDashboardAc.ClassStudentCount = totalStudents.Where(x => x.CurrentClassId == studentUser.CurrentClassId).Count(); userDashboardAc.InstituteStudentCount = totalStudents.Count; userDashboardAc.TimeTableDetails = await _timeTableManagementRepository.GetTimeTableDetailsAsync(studentUser.CurrentClassId, studentUser.SectionId.Value, academicYearId, currentUserInstituteId); userDashboardAc.UserDashboardType = UserDashboardTypeEnum.Student; userDashboardAc.ActivityList = await _staffActivityManagementRepository.GetActivitiesForStudentAsync(currentUserInstituteId, studentUser.Id); } else if (staffUser != null) { userDashboardAc.Name = staffUser.FirstName + ' ' + staffUser.MiddleName + ' ' + staffUser.LastName; userDashboardAc.Nationality = staffUser.Nationality?.Name; userDashboardAc.Institute = (await _iMSDbContext.Institutes.FirstAsync(x => x.Id == currentUserInstituteId)).Name; userDashboardAc.PhoneNumber = staffUser.MobileNumber; userDashboardAc.Email = staffUser.Email; userDashboardAc.Religion = staffUser.Religion?.Name; userDashboardAc.PersonalImage = staffUser.PersonalImage; userDashboardAc.EmployeeId = staffUser.EmployeeId; userDashboardAc.UserDashboardType = UserDashboardTypeEnum.Staff; userDashboardAc.ClassList = await _iMSDbContext.InstituteClasses.Where(x => x.InstituteId == currentUserInstituteId).ToListAsync(); userDashboardAc.SectionsList = await _iMSDbContext.Sections.Where(x => x.InstituteId == currentUserInstituteId).ToListAsync(); userDashboardAc.ActivityList = await _staffActivityManagementRepository.GetActivitiesForStaffAsync(currentUserInstituteId, staffUser.Id); userDashboardAc.InstituteStudentCount = totalStudents.Count; } return(userDashboardAc); }
/// <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>(); } }
/// <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; } }