/// <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 updating the details of logged in user /// </summary> /// <param name="id"></param> /// <param name="updatedUserAc"></param> /// <returns></returns> public async Task UpdateLoggedInUserProfileDetails(UpdateUserAc updatedUserAc, ApplicationUser currentUser) { ApplicationUser existingUser = _iMSDbContext.Users.First(x => x.Id.Equals(currentUser.Id)); existingUser.UpdatedBy = currentUser.Id; existingUser.UpdatedOn = DateTime.UtcNow; existingUser.Name = updatedUserAc.Name; await _userManager.UpdateAsync(existingUser); #region Set bell notification if (!await _userManager.IsInRoleAsync(currentUser, "SuperAdmin")) { // To the recipient NotificationAc notificationAc = new NotificationAc { NotificationMessage = "Profile Updated", NotificationTo = null, NotificationDetails = "You have successfully updated your profile", NotificationUserMappingsList = new List <NotificationUserMappingAc> { new NotificationUserMappingAc { UserId = currentUser.Id } } }; int currentUserInstituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(currentUser.Id, true); await _notificationManagementRepository.AddNotificationAsync(notificationAc, currentUserInstituteId, currentUser); notificationAc.NotificationUserMappingsList = new List <NotificationUserMappingAc>(); // To the admin if (!await _userManager.IsInRoleAsync(currentUser, "Admin")) { string instituteAdminId = (await _iMSDbContext.Institutes.FirstAsync(x => x.Id == currentUserInstituteId)).AdminId; notificationAc.NotificationDetails = string.Format("{0} has updated profile", currentUser.Name); notificationAc.NotificationUserMappingsList.Add(new NotificationUserMappingAc { UserId = instituteAdminId }); await _notificationManagementRepository.AddNotificationAsync(notificationAc, currentUserInstituteId, currentUser); } } #endregion }
/// <summary> /// Method for creating notification - RS /// </summary> /// <param name="instituteId"></param> /// <param name="currentUser"></param> /// <param name="circularNotice"></param> /// <returns></returns> private async Task AddNotificationsAsync(int instituteId, ApplicationUser currentUser, CircularNoticeAc circularNotice) { NotificationAc notificationAc = new NotificationAc { NotificationDetails = circularNotice.Description, NotificationMessage = circularNotice.Message, NotificationUserMappingsList = new List <NotificationUserMappingAc>() }; if (circularNotice.NoticeTo == NoticeToEnum.AllStaffs) { notificationAc.NotificationTo = NoticeToEnum.AllStaffs; } else if (circularNotice.NoticeTo == NoticeToEnum.AllStudents) { notificationAc.NotificationTo = NoticeToEnum.AllStudents; } else { notificationAc.NotificationTo = null; foreach (CircularNoticeRecipientAc recipient in circularNotice.CircularNoticeRecipientsList) { notificationAc.NotificationUserMappingsList.Add(new NotificationUserMappingAc { UserId = recipient.RecipientId }); } } await _notificationManagementRepository.AddNotificationAsync(notificationAc, instituteId, currentUser); }
/// <summary> /// Method for creating notification - RS /// </summary> /// <param name="instituteId"></param> /// <param name="currentUser"></param> /// <param name="staffPlanner"></param> /// <returns></returns> private async Task AddNotificationsAsync(int instituteId, ApplicationUser currentUser, StaffPlannerAc staffPlanner) { NotificationAc notificationAc = new NotificationAc { NotificationDetails = staffPlanner.Description, NotificationMessage = staffPlanner.Name, NotificationUserMappingsList = new List <NotificationUserMappingAc>() }; notificationAc.NotificationTo = null; foreach (StaffPlannerAttendeeMappingAc attendee in staffPlanner.PlannerAttendeeList) { notificationAc.NotificationUserMappingsList.Add(new NotificationUserMappingAc { UserId = attendee.AttendeeId }); } await _notificationManagementRepository.AddNotificationAsync(notificationAc, instituteId, currentUser); }
/// <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>(); } }
public async Task <IActionResult> ChangePassword([FromBody] ChangePasswordAc changePasswordAc) { if (ModelState.IsValid) { ApplicationUser currentUser = await _userManager.FindByNameAsync(User.Identity.Name); if (await _userManager.CheckPasswordAsync(currentUser, changePasswordAc.NewPassword)) { return(Ok(new { Message = "Can't set the existing password as new password", HasError = true })); } IdentityResult result = await _userManager.ChangePasswordAsync(currentUser, changePasswordAc.OldPassword, changePasswordAc.NewPassword); string message = result.Succeeded ? "Password updated successfully" : "Incorrect old password"; if (result.Succeeded) { #region Send Mail/Message var instituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(currentUser.Id, true); await _templateManagementRepository.TriggerMailOrMessageAsync(instituteId, TemplateTypeEnum.ChangePassword, TemplateFormatEnum.Email, currentUser); await _templateManagementRepository.TriggerMailOrMessageAsync(instituteId, TemplateTypeEnum.ChangePassword, TemplateFormatEnum.Sms, currentUser); #endregion #region Set bell notification if (!await _userManager.IsInRoleAsync(currentUser, "SuperAdmin")) { // To the recipient NotificationAc notificationAc = new NotificationAc { NotificationMessage = "Password Updated", NotificationTo = null, NotificationDetails = "You have successfully changed your password", NotificationUserMappingsList = new List <NotificationUserMappingAc> { new NotificationUserMappingAc { UserId = currentUser.Id } } }; int currentUserInstituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(currentUser.Id, true); await _notificationManagementRepository.AddNotificationAsync(notificationAc, currentUserInstituteId, currentUser); notificationAc.NotificationUserMappingsList = new List <NotificationUserMappingAc>(); // To the admin if (!await _userManager.IsInRoleAsync(currentUser, "Admin")) { string instituteAdminId = (await _iMSDbContext.Institutes.FirstAsync(x => x.Id == currentUserInstituteId)).AdminId; notificationAc.NotificationDetails = string.Format("{0} has changed password", currentUser.Name); notificationAc.NotificationUserMappingsList.Add(new NotificationUserMappingAc { UserId = instituteAdminId }); await _notificationManagementRepository.AddNotificationAsync(notificationAc, currentUserInstituteId, currentUser); } } #endregion } return(Ok(new { Message = message, HasError = !result.Succeeded })); } else if (string.IsNullOrEmpty(changePasswordAc.OldPassword)) { return(Ok(new { Message = "Old Password can not be null or empty", HasError = true })); } else { return(Ok(new { Message = "Password can not be null or empty", HasError = true })); } }