Exemple #1
0
        public ActionResult NewStaff()
        {
            var viewmodel = new StaffLeave();

            viewmodel.typeList =
                db.leaves.OrderBy(x => x.name).Select(x => new SelectListItem()
            {
                Text = x.name, Value = x.id.ToString()
            });
            if (viewmodel.typeList.Any())
            {
                viewmodel.annualTotal =
                    db.leaves.Single(x => x.id.ToString() == viewmodel.typeList.First().Value).defaultTotal;
            }
            return(View("EditStaff", viewmodel));
        }
Exemple #2
0
        /// <summary>
        /// Method to apply Staff leave - SS
        /// </summary>
        /// <param name="addStaffLeave">leave detail</param>
        /// <param name="instituteId">institute id</param>
        /// <returns>response</returns>
        public async Task <StaffLeaveResponse> AddStaffLeaveAsync(AddStaffLeaveAc addStaffLeave, int instituteId, ApplicationUser currentUser)
        {
            if (string.IsNullOrEmpty(addStaffLeave.Reason.Trim()))
            {
                return new StaffLeaveResponse()
                       {
                           HasError = true, Message = "Leave reason can't be empty", ErrorType = StaffLeaveResponseType.Reason
                       }
            }
            ;
            else
            {
                if (!await _iMSDbContext.StaffBasicPersonalInformation.AnyAsync(x => x.Id == addStaffLeave.StaffId && x.InstituteId == instituteId))
                {
                    return new StaffLeaveResponse()
                           {
                               HasError = true, Message = "Staff not found", ErrorType = StaffLeaveResponseType.StaffId
                           }
                }
                ;
                else
                {
                    if (!await _iMSDbContext.LeaveTypes.AnyAsync(x => x.Id == addStaffLeave.LeaveTypeId && x.InstituteId == instituteId))
                    {
                        return new StaffLeaveResponse()
                               {
                                   HasError = true, Message = "Leave type not found", ErrorType = StaffLeaveResponseType.LeaveTypeId
                               }
                    }
                    ;
                    else
                    {
                        if (!await _iMSDbContext.LeaveStatuses.AnyAsync(x => x.Id == addStaffLeave.StatusId && x.InstituteId == instituteId))
                        {
                            return new StaffLeaveResponse()
                                   {
                                       HasError = true, Message = "Status not found", ErrorType = StaffLeaveResponseType.StatusId
                                   }
                        }
                        ;
                        else
                        {
                            if (!await _iMSDbContext.UserInstituteMappings.AnyAsync(x => x.UserId == addStaffLeave.ApprovedById && x.InstituteId == instituteId))
                            {
                                return new StaffLeaveResponse()
                                       {
                                           HasError = true, Message = "Staff not found", ErrorType = StaffLeaveResponseType.ApprovedById
                                       }
                            }
                            ;
                            else
                            {
                                var currentAcademicYear = await _iMSDbContext.InstituteAcademicYears.FirstAsync(x => x.IsActive && x.InstituteId == instituteId);

                                var leave = new StaffLeave()
                                {
                                    ApprovedById   = addStaffLeave.ApprovedById,
                                    CreatedOn      = DateTime.UtcNow,
                                    EndDate        = addStaffLeave.EndDate,
                                    FromDate       = addStaffLeave.FromDate,
                                    LeaveTypeId    = addStaffLeave.LeaveTypeId,
                                    StatusId       = addStaffLeave.StatusId,
                                    Reason         = addStaffLeave.Reason,
                                    StaffId        = addStaffLeave.StaffId,
                                    AcademicYearId = currentAcademicYear.Id
                                };
                                _iMSDbContext.StaffLeaves.Add(leave);
                                await _iMSDbContext.SaveChangesAsync();

                                #region Send Mail/Message

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

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

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

                                #endregion

                                await SendBellNotificationsForStaffssLeavesAsync(currentUser, addStaffLeave.LeaveTypeId, addStaffLeave.StaffId, instituteId);

                                return(new StaffLeaveResponse()
                                {
                                    HasError = false, Message = "Leave applied succesfully"
                                });
                            }
                        }
                    }
                }
            }
        }
Exemple #3
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);
        }
Exemple #4
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;
            }
        }