コード例 #1
0
        /// <summary>
        /// Method for fetching the list of users
        /// </summary>
        /// <returns></returns>
        public async Task <List <UserAc> > GetAllUsersAsync(ApplicationUser currentUser)
        {
            int currentUserInstituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(currentUser.Id, true);

            List <ApplicationUser> usersList = await _iMSDbContext.Users.ToListAsync();

            List <UserAc> usersAcList = new List <UserAc>();

            foreach (ApplicationUser user in usersList)
            {
                List <UserGroupMapping> userGroupMappingsList = await _iMSDbContext.UserGroupMapping.Include(x => x.UserGroup).Where(x => x.UserId.Equals(user.Id)).ToListAsync();

                Institute userInstitute = (await _iMSDbContext.UserInstituteMappings.Include(x => x.Institute).FirstOrDefaultAsync(x => x.UserId.Equals(user.Id) && x.InstituteId == currentUserInstituteId))?.Institute;
                if (userGroupMappingsList.Count > 0)
                {
                    if (userInstitute != null)
                    {
                        usersAcList.Add(new UserAc
                        {
                            Id              = user.Id,
                            Name            = user.Name,
                            InstituteId     = userInstitute.Id,
                            Institute       = userInstitute.Name,
                            Email           = user.Email,
                            UserGroupIdList = userGroupMappingsList.Select(x => x.UserGroupId).ToList(),
                            UserGroup       = string.Join(", ", userGroupMappingsList.Select(x => x.UserGroup.Name))
                        });
                    }
                }
            }

            return(usersAcList);
        }
コード例 #2
0
        public async Task <IActionResult> AddNewUserGroupAsync([FromBody] AddUserGroupAc newUserGroupAc)
        {
            ApplicationUser currentUser = await _userManager.FindByNameAsync(User.Identity.Name);

            int currentUserInstituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(currentUser.Id, true);

            UserGroup existingUserGroup = await _iMSDbContext.UserGroups.FirstOrDefaultAsync(x => x.Code.Equals(newUserGroupAc.Code) && x.InstituteId == currentUserInstituteId);

            if (existingUserGroup != null)
            {
                return(Ok(new { Message = "User Role already exists with this code", HasError = true }));
            }

            if (ModelState.IsValid)
            {
                await _userGroupManagementRepository.AddNewUserGroupAsync(newUserGroupAc, currentUser);

                return(Ok(new { Message = "New User Role Added Successfully" }));
            }
            else
            {
                if (string.IsNullOrEmpty(newUserGroupAc.Code))
                {
                    return(Ok(new { Message = "User Role Code can't be empty", HasError = true }));
                }
                else
                {
                    return(Ok(new { Message = "User Role Name can't be empty", HasError = true }));
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Method to add or update attendance - SS
        /// </summary>
        /// <param name="staffAttendances">Staff attendance detail</param>
        /// <param name="loggedInUser">logged in user</param>
        public async Task AddStaffAttendanceAsync(List <AddStaffAttendanceManagementWrapperAc> staffAttendances, ApplicationUser loggedInUser)
        {
            var instituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(loggedInUser.Id, true);

            var academicYear = await _iMSDbContext.InstituteAcademicYears.FirstOrDefaultAsync(x => x.InstituteId == instituteId && x.IsActive);

            List <StaffAttendance> toBeDeleted = new List <StaffAttendance>();
            List <StaffAttendance> toBeAdded   = new List <StaffAttendance>();

            foreach (var attendance in staffAttendances)
            {
                toBeDeleted.AddRange(await _iMSDbContext.StaffAttendances.Where(x => x.StaffId == attendance.StaffId &&
                                                                                x.AttendanceDate >= attendance.AttendanceDates.First() && x.AttendanceDate <= attendance.AttendanceDates.Last()).ToListAsync());
                for (int i = 0; i < attendance.AttendanceDates.Count; i++)
                {
                    toBeAdded.Add(new StaffAttendance()
                    {
                        AttendanceDate = attendance.AttendanceDates[i],
                        AttendanceType = EnumHelperService.GetValueFromDescription <AttendanceType>(attendance.AttendanceType[i]),
                        CreatedOn      = DateTime.UtcNow,
                        StaffId        = attendance.StaffId,
                        UpdatedById    = loggedInUser.Id,
                        UpdatedOn      = DateTime.UtcNow,
                        AcademicYearId = academicYear?.Id
                    });
                }
            }
            _iMSDbContext.StaffAttendances.RemoveRange(toBeDeleted);
            _iMSDbContext.StaffAttendances.AddRange(toBeAdded);
            await _iMSDbContext.SaveChangesAsync();
        }
コード例 #4
0
        /// <summary>
        /// Method for fetching the list of all activities
        /// </summary>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public async Task <List <StaffPlannerAc> > GetAllStaffPlansAsync(ApplicationUser currentUser)
        {
            int currentUserInstituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(currentUser.Id, true);

            List <StaffPlanner> staffPlansList = await _imsDbContext.StaffPlanners
                                                 .Include(x => x.Staff)
                                                 .Where(x => x.InstituteId == currentUserInstituteId).ToListAsync();

            List <StaffPlannerAc> staffPlansListAc = new List <StaffPlannerAc>();

            foreach (StaffPlanner staffPlan in staffPlansList)
            {
                staffPlansListAc.Add(new StaffPlannerAc
                {
                    Id          = staffPlan.Id,
                    Name        = staffPlan.Name,
                    Description = staffPlan.Description,
                    DateOfPlan  = staffPlan.DateOfPlan,
                    IsActive    = staffPlan.IsActive,
                    StaffId     = staffPlan.StaffId,
                    StaffName   = staffPlan.Staff.FirstName,
                    InstituteId = staffPlan.InstituteId
                });
            }

            return(staffPlansListAc);
        }
コード例 #5
0
        /// <summary>
        /// Method for fetching the list off holidays by selected academic year
        /// </summary>
        /// <param name="academicYearId"></param>
        /// <returns></returns>
        public async Task <List <InstituteHolidayAc> > GetHolidaysByAcademicYearIdAsync(int academicYearId, ApplicationUser currentUser)
        {
            int currentUserInstituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(currentUser.Id, true);

            List <Holiday> holidaysList = await _imsDbContext.Holidays.Where(x => x.InstitutionId == currentUserInstituteId && x.AcademicYearId == academicYearId).ToListAsync();

            List <InstituteHolidayAc> holidaysListAc = new List <InstituteHolidayAc>();

            foreach (Holiday holiday in holidaysList)
            {
                holidaysListAc.Add(new InstituteHolidayAc
                {
                    Id                  = holiday.Id,
                    AcademicYearId      = holiday.AcademicYearId,
                    InstitutionId       = holiday.InstitutionId,
                    HolidayDate         = holiday.HolidayDate,
                    HolidayToDate       = holiday.HolidayToDate,
                    Description         = holiday.Description,
                    OccuranceType       = holiday.OccuranceType,
                    OccuranceTypeString = EnumHelperService.GetDescription(holiday.OccuranceType)
                });
            }

            return(holidaysListAc);
        }
コード例 #6
0
        /// <summary>
        /// Method to add bulk student relieving details
        /// </summary>
        /// <param name="addStudentRelievings">student detail</param>
        /// <param name="loggedInUser">logged in user</param>
        /// <returns>response</returns>
        public async Task <StudentRelievingManagementResponse> AddStudentRelievingAsync(List <AddStudentRelievingManagementAc> addStudentRelievings, ApplicationUser loggedInUser)
        {
            List <StudentRelievingMapping> studentRelievingMappings = new List <StudentRelievingMapping>();

            foreach (var addStudentRelieving in addStudentRelievings)
            {
                var instituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(loggedInUser.Id, true);

                studentRelievingMappings.Add(new StudentRelievingMapping()
                {
                    CreatedOn        = DateTime.UtcNow,
                    Reason           = addStudentRelieving.Reason,
                    RelievingDate    = addStudentRelieving.RelievingDate,
                    StudentId        = addStudentRelieving.StudentId,
                    StudentRelieving = EnumHelperService.GetValueFromDescription <StudentRelievingEnum>(addStudentRelieving.StudentRelieving),
                    UpdatedById      = loggedInUser.Id,
                    UpdatedOn        = DateTime.UtcNow
                });
            }
            _iMSDbContext.StudentRelievingMappings.AddRange(studentRelievingMappings);
            await _iMSDbContext.SaveChangesAsync();

            return(new StudentRelievingManagementResponse()
            {
                Message = "Student details updated successfully", HasError = false
            });
        }
コード例 #7
0
        /// <summary>
        /// Method for fetching the list of all activities - RS
        /// </summary>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public async Task <List <StaffActivityAc> > GetAllActivitiesAsync(ApplicationUser currentUser)
        {
            int currentUserInstituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(currentUser.Id, true);

            List <StaffActivity> staffActivitiesList = await _imsDbContext.StaffActivities
                                                       .Include(x => x.MeetingAgenda)
                                                       .Include(x => x.ActivityStatus)
                                                       .Where(x => x.InstituteId == currentUserInstituteId).ToListAsync();

            List <StaffActivityAc> staffActivitiesListAc = new List <StaffActivityAc>();

            foreach (StaffActivity staffActivity in staffActivitiesList)
            {
                staffActivitiesListAc.Add(new StaffActivityAc
                {
                    Id                 = staffActivity.Id,
                    Name               = staffActivity.Name,
                    Description        = staffActivity.Description,
                    StartDate          = staffActivity.StartDate,
                    EndDate            = staffActivity.EndDate,
                    IsActive           = staffActivity.IsActive,
                    InstituteId        = staffActivity.InstituteId,
                    ActivityStatusId   = staffActivity.ActivityStatusId,
                    ActivityStatusName = staffActivity.ActivityStatus.Name,
                    MeetingAgendaId    = staffActivity.MeetingAgendaId,
                    MeetingAgendaName  = staffActivity.MeetingAgenda.Name,
                    StartTime          = staffActivity.StartTime,
                    EndTime            = staffActivity.EndTime,
                    Location           = staffActivity.Location
                });
            }

            return(staffActivitiesListAc);
        }
コード例 #8
0
        /// <summary>
        /// Method to update auto sequence - SS
        /// </summary>
        /// <param name="updateAutoSequence">auto sequence</param>
        /// <param name="loggedInUser">logged in user detail</param>
        /// <returns>response</returns>
        public async Task <AutoSequenceGeneratorManagementResponse> UpdateAutoSequenceGeneratorAsync(UpdateAutoSequenceGeneratorManagementAc
                                                                                                     updateAutoSequence, ApplicationUser loggedInUser)
        {
            await semaphore.WaitAsync();

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

                var autoSequence = await _iMSDbContext.AutoSequenceGenerators.FirstOrDefaultAsync(x => x.Id == updateAutoSequence.Id &&
                                                                                                  x.InstituteId == instituteId);

                if (autoSequence != null)
                {
                    if (updateAutoSequence.AutoSequenceGeneratorDataTypes.Any(x => x.IsSelected && x.Name == "Text"))
                    {
                        if (string.IsNullOrEmpty(updateAutoSequence.CustomText))
                        {
                            return new AutoSequenceGeneratorManagementResponse()
                                   {
                                       HasError = true, Message = "Please add text in custom text."
                                   }
                        }
                        ;
                    }
                    autoSequence.CustomText = updateAutoSequence.CustomText;
                    autoSequence.Seperator  = EnumHelperService.GetValueFromDescription <AutoSequenceGeneratorSeperatorEnum>(updateAutoSequence.SeperatorDescription);
                    autoSequence.UpdateById = loggedInUser.Id;
                    autoSequence.UpdateDate = DateTime.UtcNow;
                    autoSequence.AutoSequenceGeneratorDataTypes = null;
                    _iMSDbContext.AutoSequenceGenerators.Update(autoSequence);
                    await _iMSDbContext.SaveChangesAsync();

                    var types = await _iMSDbContext.AutoSequenceGeneratorDataTypes.Where(x => x.AutoSequenceGeneratorId == autoSequence.Id).ToListAsync();

                    _iMSDbContext.AutoSequenceGeneratorDataTypes.RemoveRange(types);
                    await _iMSDbContext.SaveChangesAsync();

                    updateAutoSequence.AutoSequenceGeneratorDataTypes.ForEach(x => x.Id = 0);
                    _iMSDbContext.AutoSequenceGeneratorDataTypes.AddRange(updateAutoSequence.AutoSequenceGeneratorDataTypes);
                    await _iMSDbContext.SaveChangesAsync();

                    return(new AutoSequenceGeneratorManagementResponse()
                    {
                        HasError = false, Message = "Auto sequence updated successfully"
                    });
                }
                else
                {
                    return new AutoSequenceGeneratorManagementResponse()
                           {
                               HasError = true, Message = "Auto sequence not found"
                           }
                };
            }
            finally
            {
                semaphore.Release();
            }
        }
コード例 #9
0
        public async Task <IActionResult> AddorUpdateSelectedAcademicYearAsync(int academicYearId)
        {
            var user = await _userManager.FindByNameAsync(User.Identity.Name);

            var instituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(user.Id, true);

            if (await _iMSDbContext.InstituteAcademicYears.AnyAsync(x => x.Id == academicYearId && x.InstituteId == instituteId))
            {
                var selected = await _iMSDbContext.SelectedAcademicYears.FirstOrDefaultAsync(x => x.UserId == user.Id && x.AcademicYear.InstituteId
                                                                                             == instituteId);

                if (selected == null)
                {
                    selected = new SelectedAcademicYear()
                    {
                        AcademicYearId = academicYearId,
                        CreatedOn      = DateTime.UtcNow,
                        UserId         = user.Id
                    };
                    _iMSDbContext.SelectedAcademicYears.Add(selected);
                }
                else
                {
                    selected.AcademicYearId = academicYearId;
                    _iMSDbContext.SelectedAcademicYears.Update(selected);
                }
                await _iMSDbContext.SaveChangesAsync();

                return(Ok());
            }
            else
            {
                return(Ok(new { Message = "Academic year not found" }));
            }
        }
コード例 #10
0
        /// <summary>
        /// Method to update student fee - SS
        /// </summary>
        /// <param name="studentFeeComponents">student fee components</param>
        /// <param name="studentFeeId">student fee id</param>
        /// <param name="loggedInUser">logged in user</param>
        /// <returns>response</returns>
        public async Task <StudentFeeResponse> UpdateStudentFeeAsync(List <StudentFeeComponent> studentFeeComponents, int studentFeeId, ApplicationUser loggedInUser)
        {
            var instituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(loggedInUser.Id, true);

            var studentFee = await _iMSDbContext.StudentFees.FirstOrDefaultAsync(x => x.Id == studentFeeId && x.Student.InstituteId == instituteId);

            if (studentFee == null)
            {
                return new StudentFeeResponse()
                       {
                           HasError = true, Message = "Student not found"
                       }
            }
            ;
            else
            {
                studentFee.UpdatedById = loggedInUser.Id;

                studentFee.UpdatedOn = DateTime.UtcNow;
                _iMSDbContext.StudentFees.Update(studentFee);
                _iMSDbContext.StudentFeeComponents.UpdateRange(studentFeeComponents);
                await _iMSDbContext.SaveChangesAsync();

                return(new StudentFeeResponse()
                {
                    HasError = false, Message = "Student fee detail updated successfully"
                });
            }
        }
コード例 #11
0
        /// <summary>
        /// Method to add vehicle repair - SS
        /// </summary>
        /// <param name="addVehicleRepair">vehicle repair</param>
        /// <param name="loggedInUser">logged in user</param>
        /// <returns>response</returns>
        public async Task <VehicleRepairManagementResponse> AddVehicleRepairAsync(AddVehicleRepairManagementAc addVehicleRepair,
                                                                                  ApplicationUser loggedInUser)
        {
            if (string.IsNullOrEmpty(addVehicleRepair.Code.Trim()))
            {
                return new VehicleRepairManagementResponse()
                       {
                           HasError = true, Message = "Code can't be empty", ErrorType = VehicleRepairManagementResponseType.Code
                       }
            }
            ;
            else
            {
                var instituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(loggedInUser.Id, true);

                if (!await _iMSDbContext.VehicleMasters.AnyAsync(x => x.Id == addVehicleRepair.VehicleId && x.InstituteId == instituteId))
                {
                    return new VehicleRepairManagementResponse()
                           {
                               HasError = true, Message = "Vehicle not found", ErrorType = VehicleRepairManagementResponseType.VehicleId
                           }
                }
                ;
                else
                {
                    if (await _iMSDbContext.VehicleRepairs.AnyAsync(x => x.Code.ToLowerInvariant() == addVehicleRepair.Code.ToLowerInvariant() && x.Vehicle.InstituteId == instituteId))
                    {
                        return new VehicleRepairManagementResponse()
                               {
                                   HasError = true, Message = "Vehicle repair code already exist, Please use unique one", ErrorType = VehicleRepairManagementResponseType.Code
                               }
                    }
                    ;
                    else
                    {
                        var repair = new VehicleRepair()
                        {
                            Code        = addVehicleRepair.Code,
                            CreatedOn   = DateTime.UtcNow,
                            Remarks     = addVehicleRepair.Remarks,
                            RepairCost  = addVehicleRepair.RepairCost,
                            RepairDate  = addVehicleRepair.RepairDate,
                            UpdatedById = loggedInUser.Id,
                            UpdatedOn   = DateTime.UtcNow,
                            VehicleId   = addVehicleRepair.VehicleId
                        };

                        _iMSDbContext.VehicleRepairs.Add(repair);
                        await _iMSDbContext.SaveChangesAsync();

                        return(new VehicleRepairManagementResponse()
                        {
                            HasError = false, Message = "Vehicle repair added successfully"
                        });
                    }
                }
            }
        }
コード例 #12
0
        /// <summary>
        /// Method to get list of student leaves - SS
        /// </summary>
        /// <param name="loggedInUser">loggedInUser</param>
        /// <returns></returns>
        public async Task <List <StudentLeave> > GetStudentLeavesAsync(ApplicationUser loggedInUser)
        {
            var instituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(loggedInUser.Id, true);

            var currentAcademicYear = await _iMSDbContext.SelectedAcademicYears.FirstAsync(x => x.UserId == loggedInUser.Id &&
                                                                                           x.AcademicYear.InstituteId == instituteId);

            return(await _iMSDbContext.StudentLeaves.Include(s => s.ApprovedBy).Include(s => s.LeaveStatus).Include(s => s.Student)
                   .Include(s => s.LeaveType).Where(x => x.Student.InstituteId == instituteId && x.AcademicYearId == currentAcademicYear.AcademicYearId).ToListAsync());
        }
コード例 #13
0
        public async Task <IActionResult> GetActivityInitialData()
        {
            ApplicationUser currentUser = await _userManager.FindByNameAsync(User.Identity.Name);

            int currentUserInstituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(currentUser.Id, true);

            // Activity Status
            List <ActivityStatus> activityStatusList = await _activityStatusManagementRepository.GetAllActivityStatusAsync(currentUserInstituteId, currentUser);

            // Meeting Agenda
            List <MeetingAgenda> meetingAgendaList = await _meetingAgendaManagementRepository.GetAllMeetingAgendasAsync(currentUserInstituteId);

            // Staffs (Attendee)
            List <StaffBasicPersonalInformation> staffsList = await _imsDbContext.StaffBasicPersonalInformation.Where(x => x.InstituteId == currentUserInstituteId).ToListAsync();

            // Students (Attendee)
            List <StudentBasicInformation> studentsList = await _staffActivityManagementRepository.GetAttendeeStudentsListAsync(currentUserInstituteId);

            // System Users (Attendee)
            List <UserAc> systemUsersList = await _staffActivityManagementRepository.GetAttendeeSystemUsersListAsync(currentUserInstituteId);

            return(Ok(new
            {
                MeetingAgendaList = meetingAgendaList,
                ActivityStatusList = activityStatusList,
                StaffsList = staffsList,
                StudentsList = studentsList,
                SystemUsersList = systemUsersList
            }));
        }
コード例 #14
0
        public async Task <IActionResult> GetAcademicYearsListAsync()
        {
            ApplicationUser currentUser = await _userManager.FindByNameAsync(User.Identity.Name);

            int currentUserInstituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(currentUser.Id, true);

            return(Ok(await _instituteAcademicYearManagementRepository.GetAcademicYearsListAsync(currentUserInstituteId)));
        }
コード例 #15
0
        /// <summary>
        /// Method to add and update vehicle driver mapping - SS
        /// </summary>
        /// <param name="vehicleDriverMapping">vehicle driver detail</param>
        /// <param name="loggedInUser">logged in user</param>
        /// <returns>response</returns>
        public async Task <VehicleDriverMappingResponse> AddOrUpdateVehicleDriverMappingAsync(AddOrUpdateVehicleDriverMappingAc
                                                                                              vehicleDriverMapping, ApplicationUser loggedInUser)
        {
            var instituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(loggedInUser.Id, true);

            if (!await _iMSDbContext.VehicleMasters.AnyAsync(x => x.InstituteId == instituteId && x.Id == vehicleDriverMapping.VehicleId))
            {
                return new VehicleDriverMappingResponse()
                       {
                           HasError = true, Message = "Vehicle not found", ErrorType = VehicleDriverMappingResponseType.VehicleId
                       }
            }
            ;
            else
            {
                var driverIds = vehicleDriverMapping.Drivers.Select(x => x.DriverId).Distinct().ToList();

                var studentCount = await _iMSDbContext.DriverMasters.CountAsync(x => x.InstituteId == instituteId &&
                                                                                driverIds.Contains(x.Id));

                if (driverIds.Count != studentCount)
                {
                    return new VehicleDriverMappingResponse()
                           {
                               HasError = true, Message = "Driver not found", ErrorType = VehicleDriverMappingResponseType.DriverId
                           }
                }
                ;
                else
                {
                    var previous = await _iMSDbContext.VehicleDriverMappings.Where(x => x.VehicleId == vehicleDriverMapping.VehicleId).ToListAsync();

                    _iMSDbContext.VehicleDriverMappings.RemoveRange(previous);
                    await _iMSDbContext.SaveChangesAsync();

                    List <DomainModel.Models.VehicleDriverMapping> vehicleDriverMappings = new List <DomainModel.Models.VehicleDriverMapping>();
                    foreach (var driver in vehicleDriverMapping.Drivers)
                    {
                        vehicleDriverMappings.Add(new DomainModel.Models.VehicleDriverMapping()
                        {
                            CreatedOn   = DateTime.UtcNow,
                            DriverId    = driver.DriverId,
                            IsPrimary   = driver.IsPrimary,
                            VehicleId   = vehicleDriverMapping.VehicleId,
                            UpdatedById = loggedInUser.Id
                        });
                    }
                    _iMSDbContext.VehicleDriverMappings.AddRange(vehicleDriverMappings);
                    await _iMSDbContext.SaveChangesAsync();

                    return(new VehicleDriverMappingResponse()
                    {
                        HasError = false, Message = "Vehicle driver detail updated successfully"
                    });
                }
            }
        }
コード例 #16
0
        /// <summary>
        /// Method to add and update student route mapping - SS
        /// </summary>
        /// <param name="studentRouteMapping">student route detail</param>
        /// <param name="loggedInUser">logged in user</param>
        /// <returns>response</returns>
        public async Task <StudentRouteMappingResponse> AddOrUpdateStudentRouteMappingAsync(AddOrUpdateStudentRouteMappingAc
                                                                                            studentRouteMapping, ApplicationUser loggedInUser)
        {
            var instituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(loggedInUser.Id, true);

            if (!await _iMSDbContext.Routes.AnyAsync(x => x.InstituteId == instituteId && x.Id == studentRouteMapping.RouteId))
            {
                return new StudentRouteMappingResponse()
                       {
                           HasError = true, Message = "Route not found", ErrorType = StudentRouteMappingResponseType.RouteId
                       }
            }
            ;
            else
            {
                var studentIds = studentRouteMapping.StudentIds.Distinct().ToList();

                var studentCount = await _iMSDbContext.StudentBasicInformation.CountAsync(x => x.InstituteId == instituteId &&
                                                                                          studentIds.Contains(x.Id));

                if (studentIds.Count != studentCount)
                {
                    return new StudentRouteMappingResponse()
                           {
                               HasError = true, Message = "Student not found", ErrorType = StudentRouteMappingResponseType.StudentId
                           }
                }
                ;
                else
                {
                    var previous = await _iMSDbContext.StudentRouteMappings.Where(x => x.RouteId == studentRouteMapping.RouteId).ToListAsync();

                    _iMSDbContext.StudentRouteMappings.RemoveRange(previous);
                    await _iMSDbContext.SaveChangesAsync();

                    List <DomainModel.Models.StudentRouteMapping> studentRouteMappings = new List <DomainModel.Models.StudentRouteMapping>();
                    foreach (var student in studentRouteMapping.StudentIds)
                    {
                        studentRouteMappings.Add(new DomainModel.Models.StudentRouteMapping()
                        {
                            CreatedOn   = DateTime.UtcNow,
                            RouteId     = studentRouteMapping.RouteId,
                            StudentId   = student,
                            UpdatedById = loggedInUser.Id
                        });
                    }
                    _iMSDbContext.StudentRouteMappings.AddRange(studentRouteMappings);
                    await _iMSDbContext.SaveChangesAsync();

                    return(new StudentRouteMappingResponse()
                    {
                        HasError = false, Message = "Student route detail updated successfully"
                    });
                }
            }
        }
コード例 #17
0
 /// <summary>
 /// Method to add vehicle break down - SS
 /// </summary>
 /// <param name="addVehicleBreakDown">vehicle break down</param>
 /// <param name="loggedInUser">logged in user</param>
 /// <returns>response</returns>
 public async Task<VehicleBreakDownManagementResponse> AddVehicleBreakDownAsync(AddVehicleBreakDownManagementAc addVehicleBreakDown,
     ApplicationUser loggedInUser)
 {
     if (string.IsNullOrEmpty(addVehicleBreakDown.Code.Trim()))
         return new VehicleBreakDownManagementResponse() { HasError = true, Message = "Code can't be empty", ErrorType = VehicleBreakDownManagementResponseType.Code };
     else
     {
         var instituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(loggedInUser.Id, true);
         if (!await _iMSDbContext.VehicleMasters.AnyAsync(x => x.Id == addVehicleBreakDown.VehicleId && x.InstituteId == instituteId))
             return new VehicleBreakDownManagementResponse() { HasError = true, Message = "Vehicle not found", ErrorType = VehicleBreakDownManagementResponseType.VehicleId };
         else
         {
             if (!await _iMSDbContext.DriverMasters.AnyAsync(x => x.Id == addVehicleBreakDown.DriverId && x.InstituteId == instituteId))
                 return new VehicleBreakDownManagementResponse() { HasError = true, Message = "Driver not found", ErrorType = VehicleBreakDownManagementResponseType.DriverId };
             else
             {
                 if (await _iMSDbContext.VehicleBreakDowns.AnyAsync(x => x.Code.ToLowerInvariant() == addVehicleBreakDown.Code.ToLowerInvariant() && x.Vehicle.InstituteId == instituteId))
                     return new VehicleBreakDownManagementResponse() { HasError = true, Message = "Vehicle break down code already exist. Please use unique one", ErrorType = VehicleBreakDownManagementResponseType.Code };
                 else
                 {
                     var BreakDown = new VehicleBreakDown()
                     {
                         BreakDownDate = addVehicleBreakDown.BreakDownDate,
                         Address = addVehicleBreakDown.Address,
                         Code = addVehicleBreakDown.Code,
                         CreatedOn = DateTime.UtcNow,
                         DriverId = addVehicleBreakDown.DriverId,
                         BreakDownDuration = addVehicleBreakDown.BreakDownDuration,
                         UpdatedById = loggedInUser.Id,
                         UpdatedOn = DateTime.UtcNow,
                         VehicleId = addVehicleBreakDown.VehicleId
                     };
                     _iMSDbContext.VehicleBreakDowns.Add(BreakDown);
                     await _iMSDbContext.SaveChangesAsync();
                     return new VehicleBreakDownManagementResponse() { HasError = false, Message = "Vehicle break down added successfully" };
                 }
             }
         }
     }
 }
コード例 #18
0
        /// <summary>
        /// Method for adding a new template - RS
        /// </summary>
        /// <param name="addedTemplate"></param>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public async Task <dynamic> AddOrUpdateTemplateAsync(AddTemplateAc addedTemplate, ApplicationUser currentUser)
        {
            if (string.IsNullOrEmpty(addedTemplate.Name.Trim()))
            {
                return new { HasError = true, Message = "Name can't be empty" }
            }
            ;
            else if (string.IsNullOrEmpty(addedTemplate.Format.Trim()))
            {
                return new { HasError = true, Message = "Format can't be empty" }
            }
            ;
            else
            {
                var instituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(currentUser.Id, true);

                var template = await _iMSDbContext.Templates.FirstOrDefaultAsync(x => x.TemplateFormat ==
                                                                                 EnumHelperService.GetValueFromDescription <TemplateFormatEnum>(addedTemplate.TemplateFormat) && x.InstituteId == instituteId &&
                                                                                 x.TemplateFeatureType == EnumHelperService.GetValueFromDescription <TemplateFeatureEnum>(addedTemplate.TemplateFeatureType) &&
                                                                                 x.TemplateType == EnumHelperService.GetValueFromDescription <TemplateTypeEnum>(addedTemplate.TemplateType));

                if (template == null)
                {
                    template = new Template
                    {
                        CreatedOn           = DateTime.UtcNow,
                        EmailBcc            = addedTemplate.EmailBcc,
                        EmailSubject        = addedTemplate.EmailSubject,
                        To                  = addedTemplate.To,
                        Name                = addedTemplate.Name,
                        TemplateFormat      = EnumHelperService.GetValueFromDescription <TemplateFormatEnum>(addedTemplate.TemplateFormat),
                        TemplateFeatureType = EnumHelperService.GetValueFromDescription <TemplateFeatureEnum>(addedTemplate.TemplateFeatureType),
                        TemplateType        = EnumHelperService.GetValueFromDescription <TemplateTypeEnum>(addedTemplate.TemplateType),
                        Format              = addedTemplate.Format,
                        InstituteId         = instituteId
                    };
                    _iMSDbContext.Templates.Add(template);
                    await _iMSDbContext.SaveChangesAsync();
                }
                else
                {
                    template.EmailBcc     = addedTemplate.EmailBcc;
                    template.EmailSubject = addedTemplate.EmailSubject;
                    template.To           = addedTemplate.To;
                    template.Name         = addedTemplate.Name;
                    template.Format       = addedTemplate.Format;
                    _iMSDbContext.Templates.Add(template);
                    await _iMSDbContext.SaveChangesAsync();
                }
                return(new { HasError = false, Message = "Template updated successfully" });
            }
        }
コード例 #19
0
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            _iMSDbContext = context.HttpContext.RequestServices.GetService <IMSDbContext>();
            _userManager  = context.HttpContext.RequestServices.GetService <UserManager <ApplicationUser> >();
            _instituteUserMappingHelperService = context.HttpContext.RequestServices.GetService <IInstituteUserMappingHelperService>();
            switch (context.HttpContext.Request.Method)
            {
            case "GET": ActionFilterType = ActionFilterType.View; break;

            case "POST": ActionFilterType = ActionFilterType.Add; break;

            case "PUT": ActionFilterType = ActionFilterType.Edit; break;

            case "DELETE": ActionFilterType = ActionFilterType.Delete; break;
            }
            ;
            var instituteId = _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(context.HttpContext.User.Identity.Name, false).Result;
            var userId      = (_userManager.FindByNameAsync(context.HttpContext.User.Identity.Name).Result).Id;
            var userGroups  = (_iMSDbContext.UserGroupMapping.Where(x => x.UserId == userId).Select(x => x.UserGroup.Id).ToListAsync()).Result;
            var permissions = _iMSDbContext.UserGroupFeatures.Where(x => userGroups.Contains(x.UserGroupId)).ToList();
            var permission  = permissions.FirstOrDefault(x => x.UserGroupFeatureChild == UserGroupFeatureChild);

            if (permission == null)
            {
                context.HttpContext.Response.StatusCode = 401;
                context.HttpContext.Response.Headers.Clear();
                var wrongResult = new { Error = "UnAuthorized" };
                context.Result = new JsonResult(wrongResult);
            }
            else
            {
                var isAllowed = false;
                switch (context.HttpContext.Request.Method)
                {
                case "GET": isAllowed = permission.CanView; break;

                case "POST": isAllowed = permission.CanAdd; break;

                case "PUT": isAllowed = permission.CanEdit; break;

                case "DELETE": isAllowed = permission.CanDelete; break;
                }
                ;
                if (!isAllowed)
                {
                    context.HttpContext.Response.StatusCode = 401;
                    context.HttpContext.Response.Headers.Clear();
                    var wrongResult = new { Error = "UnAuthorized" };
                    context.Result = new JsonResult(wrongResult);
                }
            }
        }
コード例 #20
0
        /// <summary>
        /// Method for fetching the list of all mother tongues
        /// </summary>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public async Task <List <MotherTongueAc> > GetAllMotherTonguesAsync(ApplicationUser currentUser)
        {
            int currentUserInstituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(currentUser.Id, true);

            List <MotherTongue> motherTonguesList = await _imsDbContext.MotherTongues.Where(x => x.InstituteId == currentUserInstituteId).ToListAsync();

            List <MotherTongueAc> motherTonguesListAc = new List <MotherTongueAc>();

            foreach (MotherTongue motherTongue in motherTonguesList)
            {
                motherTonguesListAc.Add(new MotherTongueAc
                {
                    Id          = motherTongue.Id,
                    Name        = motherTongue.Language,
                    Code        = motherTongue.Code,
                    Description = motherTongue.Description,
                    Status      = motherTongue.Status,
                    CreatedOn   = motherTongue.CreatedOn
                });
            }

            return(motherTonguesListAc);
        }
コード例 #21
0
        /// <summary>
        /// Method for fetching the week offs by academic year id
        /// </summary>
        /// <param name="academicYearId"></param>
        /// <returns></returns>
        public async Task <List <InstituteWeekOffAc> > GetWeekOffsByAcademicYearIdAsync(int academicYearId, ApplicationUser currentUser)
        {
            int currentUserInstituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(currentUser.Id, true);

            List <WeekOff> weekOffsList = await _imsDbContext.WeekOffs.Where(x => x.AcademicYearId == academicYearId && x.InstitutionId == currentUserInstituteId).ToListAsync();

            List <WeekDaysEnum> weekDaysEnumList = EnumHelperService.GetEnumValuesList <WeekDaysEnum>();

            List <InstituteWeekOffAc> weekOffsListAc = new List <InstituteWeekOffAc>();

            foreach (WeekDaysEnum weekDay in weekDaysEnumList)
            {
                weekOffsListAc.Add(new InstituteWeekOffAc
                {
                    AcademicYearId = academicYearId,
                    InstitutionId  = currentUserInstituteId,
                    WeekDay        = weekDay,
                    WeekDayString  = EnumHelperService.GetDescription(weekDay),
                    IsWeekOff      = weekOffsList.Any(x => x.WeekDay == weekDay)
                });
            }

            return(weekOffsListAc);
        }
コード例 #22
0
        /// <summary>
        /// Method for fetching the class-subject mappings by class id
        /// </summary>
        /// <param name="classId"></param>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public async Task <Tuple <List <StaffBasicPersonalInformation>, List <ClassSubjectMappingAc> > > GetClassSubjectMappingByClassIdAsync(int classId, ApplicationUser currentUser)
        {
            int currentUserInstituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(currentUser.Id, true);

            List <ClassSubjectMappingAc> classSubjectMappingListAc = new List <ClassSubjectMappingAc>();

            InstituteClass instituteClass = await _imsDbContext.InstituteClasses.FirstAsync(x => x.Id == classId);

            List <InstituteClassSubjectMapping> classSubjectMappingsList = await _imsDbContext.InstituteClassSubjectMappings
                                                                           .Include(x => x.InstituteClass)
                                                                           .Include(x => x.InstituteSubject)
                                                                           .Include(x => x.Faculty.User)
                                                                           .Include(x => x.AlternateFaculty.User)
                                                                           .Where(x => x.ClassId == classId && x.InstituteClass.InstituteId == currentUserInstituteId && x.InstituteSubject.InstituteId == currentUserInstituteId).ToListAsync();

            List <InstituteSubject> subjectsList = await _instituteSubjectManagementRepository.GetAllInstituteSubjectsAsync(currentUserInstituteId);

            List <StaffBasicPersonalInformation> facultiesList = await _imsDbContext.StaffBasicPersonalInformation
                                                                 .Where(x => x.InstituteId == currentUserInstituteId && x.IsTeachingStaff)
                                                                 .ToListAsync();

            // Find mappings
            foreach (InstituteSubject subject in subjectsList)
            {
                ClassSubjectMappingAc classSubjectMappingAc = new ClassSubjectMappingAc
                {
                    ClassId     = classId,
                    ClassName   = instituteClass.Name,
                    SubjectId   = subject.Id,
                    SubjectName = subject.Name,
                    IsMapped    = classSubjectMappingsList.Any(x => x.ClassId == classId && x.SubjectId == subject.Id)
                };

                if (classSubjectMappingAc.IsMapped)
                {
                    InstituteClassSubjectMapping classSubjectMapping = classSubjectMappingsList.First(x => x.ClassId == classId && x.SubjectId == subject.Id);
                    classSubjectMappingAc.Id                   = classSubjectMapping.Id;
                    classSubjectMappingAc.FacultyId            = classSubjectMapping.FacultyId;
                    classSubjectMappingAc.AlternateFacultyId   = classSubjectMapping.AlternateFacultyId;
                    classSubjectMappingAc.FacultyName          = classSubjectMapping.Faculty.FirstName;
                    classSubjectMappingAc.AlternateFacultyName = classSubjectMapping.AlternateFaculty.FirstName;
                }

                classSubjectMappingListAc.Add(classSubjectMappingAc);
            }

            return(new Tuple <List <StaffBasicPersonalInformation>, List <ClassSubjectMappingAc> >(facultiesList, classSubjectMappingListAc));
        }
コード例 #23
0
        /// <summary>
        /// Method to get list of student promotion - SS
        /// </summary>
        /// <param name="loggedInUser">loggedInUser</param>
        /// <returns>list of promoted student</returns>
        public async Task <List <StudentPromotionMapping> > GetAllStudentPromotionAsync(ApplicationUser loggedInUser)
        {
            var instituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(loggedInUser.Id, true);

            var academicYear = await _iMSDbContext.SelectedAcademicYears.FirstOrDefaultAsync(x => x.UserId == loggedInUser.Id &&
                                                                                             x.AcademicYear.InstituteId == instituteId);

            var list = (await _iMSDbContext.StudentPromotionMappings.Include(a => a.Student).Include(a => a.CurrentClass)
                        .Include(a => a.CurrentSection).Include(a => a.PromotedToClass).Include(a => a.PromotedToSection)
                        .Where(x => x.Student.InstituteId == instituteId).ToListAsync());

            if (academicYear != null)
            {
                list = list.Where(x => x.Student.CurrentAcademicYearId == academicYear.AcademicYearId).ToList();
            }
            return(list);
        }
コード例 #24
0
        /// <summary>
        /// Method to add or update homework - SS
        /// </summary>
        /// <param name="homeWork">home work</param>
        /// <param name="loggedInUser">logged in user</param>
        /// <returns>response</returns>
        public async Task <HomeworkManagementResponse> AddOrUpdateHomeworkAsync(AddHomeworkManagementAc homeWork, ApplicationUser loggedInUser)
        {
            var instituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(loggedInUser.Id, true);

            if (!await _iMSDbContext.StaffBasicPersonalInformation.AnyAsync(x => x.Id == homeWork.StaffId && x.InstituteId == instituteId))
            {
                return new HomeworkManagementResponse()
                       {
                           Message = "Staff not found", HasError = true, ErrorType = HomeworkManagementReponseType.StaffId
                       }
            }
            ;
            else if (!await _iMSDbContext.InstituteClasses.AnyAsync(x => x.Id == homeWork.ClassId && x.InstituteId == instituteId))
            {
                return new HomeworkManagementResponse()
                       {
                           Message = "Class not found", HasError = true, ErrorType = HomeworkManagementReponseType.ClassId
                       }
            }
            ;
            else if (!await _iMSDbContext.Sections.AnyAsync(x => x.Id == homeWork.SectionId && x.InstituteId == instituteId))
            {
                return new HomeworkManagementResponse()
                       {
                           Message = "Section not found", HasError = true, ErrorType = HomeworkManagementReponseType.SectionId
                       }
            }
            ;
            else
            {
                var subjectIds = homeWork.HomeworkSubjectMappings.Select(x => x.SubjectId).Distinct().ToList();

                var subjectCount = await _iMSDbContext.InstituteClassSubjectMappings.CountAsync(x => subjectIds.Contains(x.SubjectId) &&
                                                                                                x.ClassId == homeWork.ClassId && x.FacultyId == homeWork.StaffId || x.AlternateFacultyId == homeWork.StaffId);

                if (subjectIds.Count != subjectCount)
                {
                    return new HomeworkManagementResponse()
                           {
                               Message = "Subject not found", HasError = true, ErrorType = HomeworkManagementReponseType.SubjectId
                           }
                }
                ;
                else
                {
                    var homeworkTexts = homeWork.HomeworkSubjectMappings.Select(x => x.HomeworkData).ToList();

                    if (homeworkTexts.Any(x => string.IsNullOrEmpty(x.Trim())))
                    {
                        return new HomeworkManagementResponse()
                               {
                                   Message = "Home can't be empty", HasError = true, ErrorType = HomeworkManagementReponseType.HomeworkData
                               }
                    }
                    ;
                    else
                    {
                        var homework = await _iMSDbContext.Homeworks.FirstOrDefaultAsync(x => x.ClassId == homeWork.ClassId &&
                                                                                         x.StaffId == homeWork.StaffId && x.SectionId == homeWork.SectionId && x.HomeworkDate == homeWork.HomeworkDate);

                        if (homework == null)
                        {
                            homework = new Homework()
                            {
                                ClassId      = homeWork.ClassId,
                                CreatedOn    = DateTime.UtcNow,
                                HomeworkDate = homeWork.HomeworkDate,
                                SectionId    = homeWork.SectionId,
                                StaffId      = homeWork.StaffId,
                                UpdatedById  = loggedInUser.Id,
                                UpdatedOn    = DateTime.UtcNow
                            };
                            _iMSDbContext.Homeworks.Add(homework);
                            await _iMSDbContext.SaveChangesAsync();
                        }
                        else
                        {
                            homework.UpdatedById = loggedInUser.Id;
                            homework.UpdatedOn   = DateTime.UtcNow;
                            _iMSDbContext.Homeworks.Update(homework);
                            await _iMSDbContext.SaveChangesAsync();

                            var previousHomeWorkSubjects = await _iMSDbContext.HomeworkSubjectMappings.Where(x => x.HomeworkId == homework.Id).ToListAsync();

                            if (previousHomeWorkSubjects.Count != 0)
                            {
                                using (var db = await _iMSDbContext.Database.BeginTransactionAsync())
                                {
                                    await _iMSDbContext.BulkDeleteAsync(previousHomeWorkSubjects);

                                    db.Commit();
                                }
                            }
                        }
                        List <HomeworkSubjectMapping> homeworkSubjects = new List <HomeworkSubjectMapping>();
                        foreach (var homeworkSubject in homeWork.HomeworkSubjectMappings)
                        {
                            homeworkSubjects.Add(new HomeworkSubjectMapping()
                            {
                                CreatedOn    = DateTime.UtcNow,
                                HomeworkData = homeworkSubject.HomeworkData,
                                HomeworkId   = homework.Id,
                                IsSelected   = homeworkSubject.IsSelected,
                                SubjectId    = homeworkSubject.SubjectId
                            });
                        }
                        using (var db = await _iMSDbContext.Database.BeginTransactionAsync())
                        {
                            await _iMSDbContext.BulkInsertAsync(homeworkSubjects);

                            db.Commit();
                        }

                        // Set bell notification
                        await SendBellNotificationOnHomewordCreation(homeWork, loggedInUser, instituteId);

                        return(new HomeworkManagementResponse()
                        {
                            HasError = false, Message = "Homework updated successfully", Data = new { Id = homework.Id }
                        });
                    }
                }
            }
        }
コード例 #25
0
        /// <summary>
        /// Method for fetching the details of an academic year by id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <InstituteAcademicYear> GetAcademicYearByIdAsync(int id, ApplicationUser currentUser)
        {
            int currentUserInstituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(currentUser.Id, true);

            return(await _imsDbContext.InstituteAcademicYears.FirstOrDefaultAsync(x => x.Id == id && x.InstituteId == currentUserInstituteId));
        }
コード例 #26
0
        /// <summary>
        /// Method to add Leave type - SS
        /// </summary>
        /// <param name="addLeaveType">leave type</param>
        /// <param name="loggedInUser">logged in user</param>
        /// <returns>response</returns>
        public async Task <LeaveTypeManagementResponse> AddLeaveType(AddLeaveTypeManagementAc addLeaveType, ApplicationUser loggedInUser)
        {
            if (string.IsNullOrEmpty(addLeaveType.Code.Trim()))
            {
                return new LeaveTypeManagementResponse()
                       {
                           HasError = true, Message = "Code can't be empty", ErrorType = LeaveTypeManagementResponseType.Code
                       }
            }
            ;
            else if (string.IsNullOrEmpty(addLeaveType.Name.Trim()))
            {
                return new LeaveTypeManagementResponse()
                       {
                           HasError = true, Message = "Code can't be empty", ErrorType = LeaveTypeManagementResponseType.Name
                       }
            }
            ;
            else
            {
                var instituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(loggedInUser.Id, true);

                var assignedToCount = await _iMSDbContext.UserInstituteMappings.CountAsync(x => addLeaveType.LeaveAssignedTos.Contains(x.UserId) && x.InstituteId == instituteId);

                if (assignedToCount != addLeaveType.LeaveAssignedTos.Count)
                {
                    return new LeaveTypeManagementResponse()
                           {
                               HasError = true, Message = "User not found", ErrorType = LeaveTypeManagementResponseType.LeaveAssignedTos
                           }
                }
                ;
                else
                {
                    if (await _iMSDbContext.LeaveTypes.AnyAsync(x => x.InstituteId == instituteId &&
                                                                x.Code.ToLowerInvariant() == addLeaveType.Code.ToLowerInvariant()))
                    {
                        return new LeaveTypeManagementResponse()
                               {
                                   HasError = true, Message = "Leave type with same code already exist. Please use unique one", ErrorType = LeaveTypeManagementResponseType.Code
                               }
                    }
                    ;
                    else
                    {
                        var leaveType = new LeaveType()
                        {
                            Code                  = addLeaveType.Code,
                            CreatedOn             = DateTime.UtcNow,
                            Description           = addLeaveType.Description,
                            InstituteId           = instituteId,
                            LeaveAssignedTypeEnum = EnumHelperService.GetValueFromDescription <LeaveAssignedTypeEnum>(addLeaveType.LeaveAssignedTypeEnumDescription),
                            Name                  = addLeaveType.Name,
                            NumberOfAllowedLeave  = addLeaveType.NumberOfAllowedLeave,
                            UpdatedById           = loggedInUser.Id,
                            UpdatedOn             = DateTime.UtcNow
                        };

                        _iMSDbContext.LeaveTypes.Add(leaveType);
                        await _iMSDbContext.SaveChangesAsync();

                        List <LeaveAssignedTo> assignedTos = new List <LeaveAssignedTo>();
                        foreach (var user in addLeaveType.LeaveAssignedTos)
                        {
                            assignedTos.Add(new LeaveAssignedTo()
                            {
                                CreatedOn   = DateTime.UtcNow,
                                LeaveTypeId = leaveType.Id,
                                UserId      = user
                            });
                        }
                        using (var db = await _iMSDbContext.Database.BeginTransactionAsync())
                        {
                            await _iMSDbContext.BulkInsertAsync(assignedTos);

                            db.Commit();
                        }
                        return(new LeaveTypeManagementResponse()
                        {
                            HasError = false, Message = "Leave type added succesfully"
                        });
                    }
                }
            }
        }
コード例 #27
0
        /// <summary>
        /// Method to add disciplinary - SS
        /// </summary>
        /// <param name="addDisciplinary">disciplinary</param>
        /// <param name="loggedInUser">logged in user</param>
        /// <returns>response</returns>
        public async Task <DisciplinaryManagementResponse> AddDisciplinaryAsync(AddDisciplinaryManagementAc addDisciplinary,
                                                                                ApplicationUser loggedInUser)
        {
            if (string.IsNullOrEmpty(addDisciplinary.Subject.Trim()))
            {
                return new DisciplinaryManagementResponse()
                       {
                           HasError = true, Message = "Subject can't be empty", ErrorType = DisciplinaryManagementResponseType.Subject
                       }
            }
            ;
            else if (string.IsNullOrEmpty(addDisciplinary.Description.Trim()))
            {
                return new DisciplinaryManagementResponse()
                       {
                           HasError = true, Message = "Description can't be empty", ErrorType = DisciplinaryManagementResponseType.Description
                       }
            }
            ;
            else
            {
                var instituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(loggedInUser.Id, true);

                var studentsCount = await _iMSDbContext.StudentBasicInformation.CountAsync(x => addDisciplinary.StudentIds
                                                                                           .Contains(x.Id) && x.InstituteId == instituteId);

                if (studentsCount != addDisciplinary.StudentIds.Count)
                {
                    return new DisciplinaryManagementResponse()
                           {
                               HasError = true, Message = "Student not found", ErrorType = DisciplinaryManagementResponseType.StudentId
                           }
                }
                ;
                else
                {
                    if (!await _iMSDbContext.DisciplinaryStatuses.AnyAsync(x => x.InstituteId == instituteId && x.Id == addDisciplinary.StatusId))
                    {
                        return new DisciplinaryManagementResponse()
                               {
                                   HasError = true, Message = "Status not found", ErrorType = DisciplinaryManagementResponseType.StatusId
                               }
                    }
                    ;
                    else
                    {
                        List <Disciplinary> disciplinaries = new List <Disciplinary>();

                        foreach (var studentId in addDisciplinary.StudentIds)
                        {
                            disciplinaries.Add(new Disciplinary()
                            {
                                CreatedOn   = DateTime.UtcNow,
                                Date        = addDisciplinary.Date,
                                Description = addDisciplinary.Description,
                                Remarks     = addDisciplinary.Remarks,
                                StatusId    = addDisciplinary.StatusId,
                                StudentId   = studentId,
                                Subject     = addDisciplinary.Subject,
                                UpdatedById = loggedInUser.Id,
                                UpdatedOn   = DateTime.UtcNow
                            });
                        }
                        using (var db = await _iMSDbContext.Database.BeginTransactionAsync())
                        {
                            await _iMSDbContext.BulkInsertAsync(disciplinaries);

                            db.Commit();
                        }
                        return(new DisciplinaryManagementResponse()
                        {
                            HasError = false, Message = "Disciplinary added successfully", Data = disciplinaries.Select(s => s.Id)
                        });
                    }
                }
            }
        }
コード例 #28
0
        /// <summary>
        /// Method to add fee refund - SS
        /// </summary>
        /// <param name="addFeeRefund">fee refund</param>
        /// <param name="loggedInUser">logged in user</param>
        /// <returns>response</returns>
        public async Task <FeeRefundManagementResponse> AddFeeRefundAsync(AddFeeRefundManagementAc addFeeRefund, ApplicationUser loggedInUser)
        {
            await semaphore.WaitAsync();

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

                if (!await _iMSDbContext.StudentBasicInformation.AnyAsync(x => x.Id == addFeeRefund.StudentId && x.InstituteId == instituteId))
                {
                    return new FeeRefundManagementResponse()
                           {
                               HasError = true, Message = "Student not found", ErrorType = FeeRefundManagementErrorType.StudentId
                           }
                }
                ;
                else if (!await _iMSDbContext.UserInstituteMappings.AnyAsync(x => x.InstituteId == instituteId && x.UserId == addFeeRefund.IssuedById))
                {
                    return new FeeRefundManagementResponse()
                           {
                               HasError = true, Message = "Issued-by user not found", ErrorType = FeeRefundManagementErrorType.IssuedById
                           }
                }
                ;
                else
                {
                    if (string.IsNullOrEmpty(addFeeRefund.RefundNumber.Trim()))
                    {
                        return new FeeRefundManagementResponse()
                               {
                                   HasError = true, Message = "Refund number can't be empty", ErrorType = FeeRefundManagementErrorType.RefundNumber
                               }
                    }
                    ;
                    else if (string.IsNullOrEmpty(addFeeRefund.ChallanNumber.Trim()))
                    {
                        return new FeeRefundManagementResponse()
                               {
                                   HasError = true, Message = "Challan number can't be empty", ErrorType = FeeRefundManagementErrorType.ChallanNumber
                               }
                    }
                    ;
                    else if (string.IsNullOrEmpty(addFeeRefund.ChequeNumber.Trim()))
                    {
                        return new FeeRefundManagementResponse()
                               {
                                   HasError = true, Message = "Cheque number can't be empty", ErrorType = FeeRefundManagementErrorType.ChequeNumber
                               }
                    }
                    ;
                    else if (string.IsNullOrEmpty(addFeeRefund.BankName.Trim()))
                    {
                        return new FeeRefundManagementResponse()
                               {
                                   HasError = true, Message = "Bank name can't be empty", ErrorType = FeeRefundManagementErrorType.BankName
                               }
                    }
                    ;
                    else if (double.IsNaN(addFeeRefund.Amount))
                    {
                        return new FeeRefundManagementResponse()
                               {
                                   HasError = true, Message = "Amount number can't be empty and should be number", ErrorType = FeeRefundManagementErrorType.Amount
                               }
                    }
                    ;
                    else
                    {
                        if (await _iMSDbContext.FeeRefunds.AnyAsync(x => x.RefundNumber.ToLowerInvariant() == addFeeRefund.RefundNumber.ToLowerInvariant()))
                        {
                            var autoSequence = await _iMSDbContext.AutoSequenceGenerators.Include(s => s.AutoSequenceGeneratorDataTypes)
                                               .Include(d => d.Institute).FirstOrDefaultAsync(x => x.InstituteId == instituteId &&
                                                                                              x.AutoSequenceGeneratorType == AutoSequenceGeneratorTypeEnum.RefundNumber);

                            if (autoSequence == null)
                            {
                                return new FeeRefundManagementResponse()
                                       {
                                           Message = "Refund number already exist. Please use unique id", HasError = true, ErrorType = FeeRefundManagementErrorType.RefundNumber
                                       }
                            }
                            ;
                            else
                            {
                                addFeeRefund.RefundNumber = await GenerateRefundNumberAsync(autoSequence);
                            }
                        }
                        var refund = new FeeRefund()
                        {
                            Amount        = addFeeRefund.Amount,
                            BankName      = addFeeRefund.BankName,
                            ChallanNumber = addFeeRefund.ChallanNumber,
                            ChequeDate    = addFeeRefund.ChequeDate,
                            ChequeNumber  = addFeeRefund.ChequeNumber,
                            CreatedOn     = DateTime.UtcNow,
                            IssuedById    = addFeeRefund.IssuedById,
                            RefundDate    = addFeeRefund.RefundDate,
                            RefundNumber  = addFeeRefund.RefundNumber,
                            Remark        = addFeeRefund.Remark,
                            StudentId     = addFeeRefund.StudentId,
                            UpdatedById   = loggedInUser.Id,
                            UpdatedOn     = DateTime.UtcNow
                        };

                        _iMSDbContext.FeeRefunds.Add(refund);
                        await _iMSDbContext.SaveChangesAsync();

                        return(new FeeRefundManagementResponse()
                        {
                            HasError = false, Message = "Fee refund detail added successfully"
                        });
                    }
                }
            }
            finally
            {
                semaphore.Release();
            }
        }
コード例 #29
0
        /// <summary>
        /// Method to add class exam - SS
        /// </summary>
        /// <param name="addClassExam">class exam</param>
        /// <param name="loggedInUser">logged in user</param>
        /// <returns>response</returns>
        public async Task <ClassExamResponse> AddClassExamAsync(AddClassExamAc addClassExam, ApplicationUser loggedInUser)
        {
            var instituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(loggedInUser.Id, true);

            if (!await _iMSDbContext.InstituteClasses.AnyAsync(x => x.Id == addClassExam.ClassId && x.InstituteId == instituteId))
            {
                return new ClassExamResponse()
                       {
                           HasError = true, Message = "Class not found", ErrorType = ClassExamResponseType.ClassId
                       }
            }
            ;
            else if (!await _iMSDbContext.Sections.AnyAsync(x => x.Id == addClassExam.SectionId && x.InstituteId == instituteId))
            {
                return new ClassExamResponse()
                       {
                           HasError = true, Message = "Section not found", ErrorType = ClassExamResponseType.SectionId
                       }
            }
            ;
            else if (!await _iMSDbContext.ExamDefinitions.AnyAsync(x => x.Id == addClassExam.ExamId && x.InstituteId == instituteId))
            {
                return new ClassExamResponse()
                       {
                           HasError = true, Message = "Exam not found", ErrorType = ClassExamResponseType.ExamId
                       }
            }
            ;
            else
            {
                var subjectIds = addClassExam.ClassExamSubjectMappings.Select(x => x.SubjectId).Distinct().ToList();

                var subjectCount = await _iMSDbContext.InstituteSubjects.CountAsync(x => subjectIds.Contains(x.Id));

                if (subjectIds.Count != subjectCount)
                {
                    return new ClassExamResponse()
                           {
                               HasError = true, Message = "Subject not found", ErrorType = ClassExamResponseType.SubjectId
                           }
                }
                ;
                else
                {
                    var classExam = new ClassExam()
                    {
                        ClassId             = addClassExam.ClassId,
                        CreatedOn           = DateTime.UtcNow,
                        ExamId              = addClassExam.ExamId,
                        SectionId           = addClassExam.SectionId,
                        TotalAttendanceDays = addClassExam.TotalAttendanceDays,
                        UpdatedById         = loggedInUser.Id,
                        UpdatedOn           = DateTime.UtcNow
                    };

                    _iMSDbContext.ClassExams.Add(classExam);
                    await _iMSDbContext.SaveChangesAsync();

                    List <ClassExamSubjectMapping> classExamSubjects = new List <ClassExamSubjectMapping>();
                    foreach (var subject in addClassExam.ClassExamSubjectMappings)
                    {
                        classExamSubjects.Add(new ClassExamSubjectMapping()
                        {
                            ClassExamId = classExam.Id,
                            Content     = subject.Content,
                            CreatedOn   = DateTime.UtcNow,
                            EndTime     = subject.EndTime,
                            MaxScore    = subject.MaxScore,
                            MinScore    = subject.MinScore,
                            Remark      = subject.Remark,
                            StartDate   = subject.StartDate,
                            StartTime   = subject.StartTime,
                            SubjectId   = subject.SubjectId
                        });
                    }
                    _iMSDbContext.ClassExamSubjectMappings.AddRange(classExamSubjects);
                    await _iMSDbContext.SaveChangesAsync();

                    return(new ClassExamResponse()
                    {
                        HasError = false, Message = "Class exam detail added successfully"
                    });
                }
            }
        }
コード例 #30
0
        /// <summary>
        /// Method for fetching the list of all designations
        /// </summary>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public async Task <List <Designation> > GetAllDesignationsAsync(ApplicationUser currentUser)
        {
            int currentUserInstituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(currentUser.Id, true);

            return(await _imsDbContext.Designations.Where(x => x.InstituteId == currentUserInstituteId).ToListAsync());
        }