Esempio n. 1
0
        public async Task <LoginResult> Login(LoginModel login)
        {
            var result = new LoginResult();

            var user = await _userManager.Users.Include(u => u.Person)
                       .FirstOrDefaultAsync(x => x.UserName == login.Username.ToLower());

            if (user == null)
            {
                result.Fail("Username/password incorrect.");

                return(result);
            }

            var signInResult = await _signInManager.CheckPasswordSignInAsync(user, login.Password, false);

            if (!signInResult.Succeeded)
            {
                result.Fail("Username/password incorrect.");
            }
            else if (!user.Enabled)
            {
                result.Fail("Your account has been disabled. Please try again later.");
            }
            else
            {
                result.Success(BusinessMapper.Map <UserModel>(user));
            }

            return(result);
        }
Esempio n. 2
0
        public async Task Create(AcademicYearModel academicYearModel)
        {
            var academicYear = BusinessMapper.Map <AcademicYear>(academicYearModel);

            _academicYearRepository.Create(academicYear);

            await _academicYearRepository.SaveChanges();
        }
Esempio n. 3
0
        public async Task <AttendanceWeekModel> GetById(Guid attendanceWeekId)
        {
            var attendanceWeek = await _attendanceWeekRepository.GetById(attendanceWeekId);

            if (attendanceWeek == null)
            {
                throw new NotFoundException("Attendance week not found.");
            }

            return(BusinessMapper.Map <AttendanceWeekModel>(attendanceWeek));
        }
Esempio n. 4
0
        public async Task <DirectoryModel> GetById(Guid directoryId)
        {
            var directory = await _directoryRepository.GetById(directoryId);

            if (directory == null)
            {
                throw new NotFoundException("Directory not found.");
            }

            return(BusinessMapper.Map <DirectoryModel>(directory));
        }
Esempio n. 5
0
        public async Task <DocumentModel> GetDocumentById(Guid documentId)
        {
            var document = await _documentRepository.GetById(documentId);

            if (document == null)
            {
                throw new NotFoundException("Document not found.");
            }

            return(BusinessMapper.Map <DocumentModel>(document));
        }
Esempio n. 6
0
        public async Task <TaskModel> GetById(Guid taskId)
        {
            var task = await _taskRepository.GetById(taskId);

            if (task == null)
            {
                throw new NotFoundException("Task not found.");
            }

            return(BusinessMapper.Map <TaskModel>(task));
        }
Esempio n. 7
0
        public async Task <AttendanceWeekModel> GetByDate(DateTime date, bool throwIfNotFound = true)
        {
            var week = await _attendanceWeekRepository.GetByDate(date);

            if (week == null && throwIfNotFound)
            {
                throw new NotFoundException("Attendance week not found.");
            }

            return(BusinessMapper.Map <AttendanceWeekModel>(week));
        }
Esempio n. 8
0
        public async Task <AttendancePeriodModel> GetById(Guid periodId)
        {
            var period = await _periodRepository.GetById(periodId);

            if (period == null)
            {
                throw new NotFoundException("Period not found.");
            }

            return(BusinessMapper.Map <AttendancePeriodModel>(period));
        }
Esempio n. 9
0
        public async Task <PersonModel> GetByUserId(Guid userId, bool throwIfNotFound = true)
        {
            var person = await _personRepository.GetByUserId(userId);

            if (person == null && throwIfNotFound)
            {
                throw new NotFoundException("Person not found.");
            }

            return(BusinessMapper.Map <PersonModel>(person));
        }
Esempio n. 10
0
        public async Task <LogNoteModel> GetById(Guid logNoteId)
        {
            var logNote = await _logNoteRepository.GetById(logNoteId);

            if (logNote == null)
            {
                throw new NotFoundException("Log note not found.");
            }

            return(BusinessMapper.Map <LogNoteModel>(logNote));
        }
Esempio n. 11
0
        public async Task <AcademicYearModel> GetCurrent()
        {
            var acadYear = await _academicYearRepository.GetCurrent();

            if (acadYear == null)
            {
                throw new NotFoundException("Current academic year not defined.");
            }

            return(BusinessMapper.Map <AcademicYearModel>(acadYear));
        }
Esempio n. 12
0
        public async Task <RoleModel> GetRoleById(Guid roleId)
        {
            var role = await _roleManager.FindByIdAsync(roleId.ToString());

            if (role == null)
            {
                throw new NotFoundException("Role not found.");
            }

            return(BusinessMapper.Map <RoleModel>(role));
        }
Esempio n. 13
0
        public async Task <StudentModel> GetByPersonId(Guid personId, bool throwIfNotFound = true)
        {
            var student = await _studentRepository.GetByPersonId(personId);

            if (student == null && throwIfNotFound)
            {
                throw new NotFoundException("Student not found.");
            }

            return(BusinessMapper.Map <StudentModel>(student));
        }
Esempio n. 14
0
        public async Task <StudentModel> GetById(Guid studentId)
        {
            var student = await _studentRepository.GetById(studentId);

            if (student == null)
            {
                throw new NotFoundException("Student not found.");
            }

            return(BusinessMapper.Map <StudentModel>(student));
        }
Esempio n. 15
0
        public async Task <StaffMemberModel> GetByUserId(Guid userId, bool throwIfNotFound = true)
        {
            var staffMember = await _staffMemberRepository.GetByUserId(userId);

            if (staffMember == null && throwIfNotFound)
            {
                throw new NotFoundException("Staff member not found.");
            }

            return(BusinessMapper.Map <StaffMemberModel>(staffMember));
        }
Esempio n. 16
0
        public async Task <AttendanceMarkModel> Get(Guid studentId, Guid attendanceWeekId, Guid periodId)
        {
            var attendanceMark = await _attendanceMarkRepository.Get(studentId, attendanceWeekId, periodId);

            if (attendanceMark == null)
            {
                return(NoMark(studentId, attendanceWeekId, periodId));
            }

            return(BusinessMapper.Map <AttendanceMarkModel>(attendanceMark));
        }
Esempio n. 17
0
        public async Task <IEnumerable <RoleModel> > GetUserRoles(Guid userId)
        {
            var user = await _userManager.FindByIdAsync(userId.ToString());

            var roleNames = await _userManager.GetRolesAsync(user);

            var roles = new List <RoleModel>();

            foreach (var roleName in roleNames)
            {
                var role = await _roleManager.FindByNameAsync(roleName);

                roles.Add(BusinessMapper.Map <RoleModel>(role));
            }

            return(roles);
        }
Esempio n. 18
0
        public async Task <DetentionModel> GetByIncident(Guid incidentId)
        {
            var detention = await _detentionRepository.GetByIncident(incidentId);

            return(BusinessMapper.Map <DetentionModel>(detention));
        }
Esempio n. 19
0
        public async Task <AchievementModel> GetById(Guid achievementId)
        {
            var achievement = await _achievementRepository.GetById(achievementId);

            return(BusinessMapper.Map <AchievementModel>(achievement));
        }
Esempio n. 20
0
        public async Task <PersonModel> GetById(Guid personId)
        {
            var person = await _personRepository.GetById(personId);

            return(BusinessMapper.Map <PersonModel>(person));
        }
Esempio n. 21
0
        public async Task Create(StudentModel student)
        {
            _studentRepository.Create(BusinessMapper.Map <Student>(student));

            await _studentRepository.SaveChanges();
        }
Esempio n. 22
0
        public async Task <IEnumerable <PermissionModel> > GetPermissions(Guid roleId)
        {
            var permissions = await _rolePermissionRepository.GetByRole(roleId);

            return(permissions.Select(p => BusinessMapper.Map <PermissionModel>(p.Permission)));
        }
Esempio n. 23
0
        public async Task <UserModel> GetUserById(Guid userId)
        {
            var user = await _userManager.Users.FirstOrDefaultAsync(x => x.Id == userId);

            return(BusinessMapper.Map <UserModel>(user));
        }
Esempio n. 24
0
        public async Task <IncidentModel> GetById(Guid incidentId)
        {
            var incident = await _incidentRepository.GetById(incidentId);

            return(BusinessMapper.Map <IncidentModel>(incident));
        }