public async Task <IActionResult> ArchiveStaffAsync(int staffId)
        {
            var loggedInUserInstituteId = await GetUserCurrentSelectedInstituteIdAsync();

            var staff = await _iMSDbContext.StaffBasicPersonalInformation.FirstOrDefaultAsync(x => x.Id == staffId && x.InstituteId == loggedInUserInstituteId);

            if (staff != null)
            {
                staff.IsArchived = true;
                _iMSDbContext.StaffBasicPersonalInformation.Update(staff);
                await _iMSDbContext.SaveChangesAsync();

                #region Send Mail/Message
                staff = await _iMSDbContext.StaffBasicPersonalInformation.Include(s => s.Gender).Include(s => s.PermanentCity)
                        .Include(s => s.PresentCity).Include(s => s.Institute).Include(s => s.User).FirstAsync(x => x.Id == staff.Id);

                await _templateManagementRepository.TriggerMailOrMessageAsync(staff.InstituteId.Value, TemplateTypeEnum.StaffEdit,
                                                                              TemplateFormatEnum.Email, staff);

                await _templateManagementRepository.TriggerMailOrMessageAsync(staff.InstituteId.Value, TemplateTypeEnum.StaffEdit,
                                                                              TemplateFormatEnum.Sms, staff);

                #endregion
                return(Ok(new { HasError = false }));
            }
            else
            {
                return(Ok(new { HasError = true, Message = "Staff not found" }));
            }
        }
        public async Task <IActionResult> ApproveAndRejectStudentLeaveAsync([FromBody] ApproveAndRejectStudentLeaveAc approveAndReject)
        {
            var instituteId = await GetUserCurrentSelectedInstituteIdAsync();

            ApplicationUser currentUser = await _userManager.FindByNameAsync(User.Identity.Name);

            var leave = await _iMSDbContext.StudentLeaves.FirstOrDefaultAsync(x => x.Id == approveAndReject.LeaveId && x.Student.InstituteId == instituteId);

            if (leave == null)
            {
                return(Ok(new { Message = "Leave not found" }));
            }
            else
            {
                var status = await _iMSDbContext.LeaveStatuses.FirstOrDefaultAsync(x => x.Code.ToLowerInvariant() == approveAndReject.Type.ToLowerInvariant() && x.InstituteId == instituteId);

                if (status == null)
                {
                    return(Ok(new { Message = "Leave status not found" }));
                }
                else
                {
                    leave.StatusId = status.Id;
                    _iMSDbContext.StudentLeaves.Update(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.StudentLeaveApproveReject,
                                                                                  TemplateFormatEnum.Email, leave);

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

                    #endregion

                    await _leaveManagementRepository.SendBellNotificationsForStudentLeaveApproveRejectAsync(currentUser, leave, instituteId);

                    return(Ok(new { Message = "Leave updated" }));
                }
            }
        }
Exemple #3
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"
                                });
                            }
                        }
                    }
                }
            }
        }
Exemple #4
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 }));
            }
        }
Exemple #5
0
        /// <summary>
        /// Method to add fee receipts - SS
        /// </summary>
        /// <param name="addFeeReceipts">fee receipts</param>
        /// <param name="loggedInUser">logged in user</param>
        /// <returns>response</returns>
        public async Task <FeeReceiptManagementResponse> AddFeeReceiptAsync(List <AddFeeReceiptManagementAc> addFeeReceipts, ApplicationUser loggedInUser)
        {
            await semaphore.WaitAsync();

            try
            {
                var instituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(loggedInUser.Id, true);

                List <FeeReceiptComponent> feeReceiptComponents = new List <FeeReceiptComponent>();
                int orderId = 0;
                foreach (var receipt in addFeeReceipts)
                {
                    if (string.IsNullOrEmpty(receipt.ReceiptNumber.Trim()))
                    {
                        return new FeeReceiptManagementResponse()
                               {
                                   HasError = true, OrderId = orderId, Message = "Receipt number can't be empty", ErrorType = FeeReceiptManagementType.ReceiptNumber
                               }
                    }
                    ;
                    else if (string.IsNullOrEmpty(receipt.ChallanNumber.Trim()))
                    {
                        return new FeeReceiptManagementResponse()
                               {
                                   HasError = true, OrderId = orderId, Message = "Challan number can't be empty", ErrorType = FeeReceiptManagementType.ChallanNumber
                               }
                    }
                    ;
                    else
                    {
                        if (await _iMSDbContext.FeeReceipts.AnyAsync(x => x.ReceiptNumber == receipt.ReceiptNumber))
                        {
                            var autoSequence = await _iMSDbContext.AutoSequenceGenerators.Include(s => s.AutoSequenceGeneratorDataTypes)
                                               .Include(d => d.Institute).FirstOrDefaultAsync(x => x.InstituteId == instituteId &&
                                                                                              x.AutoSequenceGeneratorType == AutoSequenceGeneratorTypeEnum.ReceiptNumber);

                            if (autoSequence == null)
                            {
                                return new FeeReceiptManagementResponse()
                                       {
                                           HasError = true, OrderId = orderId, Message = "Duplicate receipt number. Please choose unique number", ErrorType = FeeReceiptManagementType.ReceiptNumber
                                       }
                            }
                            ;
                            else
                            {
                                receipt.ReceiptNumber = await GenerateFeeReceiptNumberAsync(autoSequence);
                            }
                        }
                        var feeReceipt = new FeeReceipt()
                        {
                            Amount             = receipt.Amount,
                            BankName           = receipt.BankName,
                            ChallanNumber      = receipt.ChallanNumber,
                            ChequeDate         = receipt.ChequeDate,
                            ChequeNumber       = receipt.ChequeNumber,
                            ClassId            = receipt.ClassId,
                            CreatedOn          = DateTime.UtcNow,
                            IsNewAdmission     = receipt.IsNewAdmission,
                            LateFee            = receipt.LateFee,
                            PreviousAmountPaid = receipt.PreviousAmountPaid,
                            ReceiptDate        = receipt.ReceiptDate,
                            ReceiptNumber      = receipt.ReceiptNumber,
                            ReceiptType        = EnumHelperService.GetValueFromDescription <ReceiptTypeEnum>(receipt.ReceiptType),
                            StudentId          = receipt.StudentId,
                            Total       = receipt.Total,
                            UpdatedById = loggedInUser.Id,
                            UpdatedOn   = DateTime.UtcNow,
                            Term        = receipt.Term
                        };

                        _iMSDbContext.FeeReceipts.AddRange(feeReceipt);
                        await _iMSDbContext.SaveChangesAsync();

                        #region Send Mail/Message
                        feeReceipt = await _iMSDbContext.FeeReceipts.Include(s => s.Student).FirstAsync(s => s.Id == feeReceipt.Id);

                        await _templateManagementRepository.TriggerMailOrMessageAsync(instituteId, TemplateTypeEnum.FeePaymentAdd,
                                                                                      TemplateFormatEnum.Email, feeReceipt);

                        await _templateManagementRepository.TriggerMailOrMessageAsync(instituteId, TemplateTypeEnum.FeePaymentAdd,
                                                                                      TemplateFormatEnum.Sms, feeReceipt);

                        #endregion
                        for (int i = 0; i < receipt.FeeReceiptComponents.Count; i++)
                        {
                            feeReceiptComponents.Add(new FeeReceiptComponent()
                            {
                                Amount      = receipt.FeeReceiptComponents[i].Amount,
                                CreatedOn   = DateTime.UtcNow,
                                FeeReciptId = feeReceipt.Id,
                                Name        = receipt.FeeReceiptComponents[i].Name,
                                OrderId     = i,
                            });
                        }
                    }
                    orderId++;
                }
                _iMSDbContext.FeeReceiptComponents.AddRange(feeReceiptComponents);
                await _iMSDbContext.SaveChangesAsync();

                return(new FeeReceiptManagementResponse()
                {
                    HasError = false, Message = "Fee receipt added successfully"
                });
            }
            finally
            {
                semaphore.Release();
            }
        }