/// <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);
        }
Esempio n. 2
0
        /// <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);
            }
        }
Esempio n. 3
0
        /// <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 adding a new notification - RS
        /// </summary>
        /// <param name="addedNotificationAc"></param>
        /// <param name="instituteId"></param>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public async Task AddNotificationAsync(NotificationAc addedNotificationAc, int instituteId, ApplicationUser currentUser)
        {
            // Add new notification
            Notification addedNotification = new Notification
            {
                CreatedById         = currentUser.Id,
                CreatedOn           = DateTime.UtcNow,
                InstituteId         = instituteId,
                NotificationDetails = addedNotificationAc.NotificationDetails,
                NotificationMessage = addedNotificationAc.NotificationMessage
            };

            _imsDbContext.Notifications.Add(addedNotification);
            await _imsDbContext.SaveChangesAsync();

            // Add user-notification mappings
            List <NotificationUserMapping> notificationUserMappings = new List <NotificationUserMapping>();
            List <string> userIdList = new List <string>();

            if (addedNotificationAc.NotificationTo == NoticeToEnum.AllStaffs)
            {
                userIdList = await _imsDbContext.StaffBasicPersonalInformation
                             .Where(x => x.InstituteId == instituteId && !x.IsArchived)
                             .Select(x => x.UserId)
                             .ToListAsync();
            }
            else if (addedNotificationAc.NotificationTo == NoticeToEnum.AllStudents)
            {
                userIdList = await _imsDbContext.StudentBasicInformation
                             .Where(x => x.InstituteId == instituteId && !x.IsActive && !x.IsArchived)
                             .Select(x => x.UserId)
                             .ToListAsync();
            }
            else
            {
                userIdList = addedNotificationAc.NotificationUserMappingsList.Select(x => x.UserId).ToList();
            }

            foreach (string userId in userIdList)
            {
                notificationUserMappings.Add(new NotificationUserMapping
                {
                    NotificationId     = addedNotification.Id,
                    UserId             = userId,
                    IsNotificationRead = false,
                    CreatedOn          = DateTime.Now
                });
            }

            _imsDbContext.NotificationUserMappings.AddRange(notificationUserMappings);
            await _imsDbContext.SaveChangesAsync();
        }
Esempio n. 5
0
        /// <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="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);
        }
Esempio n. 7
0
        /// <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 list of notifications for a particular user - RS
        /// </summary>
        /// <param name="currentUserId"></param>
        /// <param name="instituteId"></param>
        /// <param name="isUnreadNotifications">
        /// Send 'true' for fetching only unread notifications
        /// Send 'false' for fetching all notifications
        /// </param>
        /// <returns></returns>
        public async Task <List <NotificationAc> > GetNotificationsForCurrentUserAsync(string currentUserId, int instituteId, bool isUnreadNotifications)
        {
            List <NotificationAc> notificationsAcList = new List <NotificationAc>();

            List <NotificationUserMapping> allUnreadNotificationDetailsList = await _imsDbContext.NotificationUserMappings
                                                                              .Include(x => x.Notification)
                                                                              .Where(x => x.UserId == currentUserId && x.Notification.InstituteId == instituteId)
                                                                              .ToListAsync();

            if (isUnreadNotifications)
            {
                allUnreadNotificationDetailsList = allUnreadNotificationDetailsList.Where(x => !x.IsNotificationRead).ToList();
            }

            List <Notification> allUnreadNotificationsList = allUnreadNotificationDetailsList.Select(x => x.Notification).Distinct().ToList();

            foreach (Notification notification in allUnreadNotificationsList)
            {
                NotificationAc notificationAc = new NotificationAc
                {
                    Id = notification.Id,
                    NotificationCreationDate     = notification.CreatedOn,
                    NotificationDetails          = notification.NotificationDetails,
                    NotificationMessage          = notification.NotificationMessage,
                    NotificationUserMappingsList = new List <NotificationUserMappingAc>(),
                    IsReadByUser = allUnreadNotificationDetailsList.First(x => x.NotificationId == notification.Id).IsNotificationRead
                };

                notificationsAcList.Add(notificationAc);
            }

            return(notificationsAcList
                   .OrderByDescending(x => x.NotificationCreationDate)
                   .OrderBy(x => x.IsReadByUser)
                   .ToList());
        }
Esempio n. 9
0
        /// <summary>
        /// Method for sending bell notification for students' leaves - RS
        /// </summary>
        /// <param name="currentUser"></param>
        /// <param name="leaveTypeId"></param>
        /// <param name="leaveForStudentId"></param>
        /// <param name="instituteId"></param>
        /// <returns></returns>
        private async Task SendBellNotificationsForStudentsLeavesAsync(ApplicationUser currentUser, int leaveTypeId, int leaveForStudentId, int instituteId)
        {
            StudentBasicInformation studentUser = await _iMSDbContext.StudentBasicInformation
                                                  .Include(x => x.User)
                                                  .Include(x => x.CurrentClass)
                                                  .ThenInclude(x => x.ClassTeacher)
                                                  .ThenInclude(x => x.User)
                                                  .Include(x => x.Institute)
                                                  .FirstOrDefaultAsync(x => x.UserId == currentUser.Id);

            LeaveType leaveType = await _iMSDbContext.LeaveTypes.FirstAsync(x => x.Id == 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 == leaveForStudentId));

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

            // Created by the admin
            if (studentUser == null)
            {
                // For Student
                notificationAc.NotificationDetails = string.Format("Your {0} has been applied successfully", leaveType.Name);
                notificationAc.NotificationUserMappingsList.Add(new NotificationUserMappingAc
                {
                    UserId = leaveForStudent.UserId
                });

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

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

                // For Class Teacher
                if (leaveForStudent.CurrentClass.ClassTeacherId.HasValue)
                {
                    notificationAc.NotificationDetails = string.Format("{0} has been applied from {1} of class {2}",
                                                                       leaveType.Name, leaveForStudent.FirstName, leaveForStudent.CurrentClass.Name);
                    notificationAc.NotificationUserMappingsList.Add(new NotificationUserMappingAc
                    {
                        UserId = leaveForStudent.CurrentClass.ClassTeacher?.UserId
                    });

                    await _notificationManagementRepository.AddNotificationAsync(notificationAc, instituteId, currentUser);
                }
            }
            // Created by the student
            else
            {
                // For Student
                notificationAc.NotificationDetails = string.Format("Your {0} has been applied successfully", leaveType.Name);
                notificationAc.NotificationUserMappingsList.Add(new NotificationUserMappingAc
                {
                    UserId = studentUser.UserId
                });

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

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

                // For Class Teacher
                if (studentUser.CurrentClass.ClassTeacherId.HasValue)
                {
                    notificationAc.NotificationDetails = string.Format("New {0} request from {1} of class {2}",
                                                                       leaveType.Name, studentUser.FirstName, studentUser.CurrentClass.Name);
                    notificationAc.NotificationUserMappingsList.Add(new NotificationUserMappingAc
                    {
                        UserId = studentUser.CurrentClass.ClassTeacher?.UserId
                    });

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

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

                // For Admin
                notificationAc.NotificationDetails = string.Format("New {0} request from {1} of class {2}",
                                                                   leaveType.Name, studentUser.FirstName, studentUser.CurrentClass.Name);
                notificationAc.NotificationUserMappingsList.Add(new NotificationUserMappingAc
                {
                    UserId = studentUser.Institute.AdminId
                });

                await _notificationManagementRepository.AddNotificationAsync(notificationAc, instituteId, currentUser);
            }
        }
Esempio n. 10
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>();
            }
        }
Esempio n. 11
0
        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 }));
            }
        }