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); }
public async Task Create(AcademicYearModel academicYearModel) { var academicYear = BusinessMapper.Map <AcademicYear>(academicYearModel); _academicYearRepository.Create(academicYear); await _academicYearRepository.SaveChanges(); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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); }
public async Task <DetentionModel> GetByIncident(Guid incidentId) { var detention = await _detentionRepository.GetByIncident(incidentId); return(BusinessMapper.Map <DetentionModel>(detention)); }
public async Task <AchievementModel> GetById(Guid achievementId) { var achievement = await _achievementRepository.GetById(achievementId); return(BusinessMapper.Map <AchievementModel>(achievement)); }
public async Task <PersonModel> GetById(Guid personId) { var person = await _personRepository.GetById(personId); return(BusinessMapper.Map <PersonModel>(person)); }
public async Task Create(StudentModel student) { _studentRepository.Create(BusinessMapper.Map <Student>(student)); await _studentRepository.SaveChanges(); }
public async Task <IEnumerable <PermissionModel> > GetPermissions(Guid roleId) { var permissions = await _rolePermissionRepository.GetByRole(roleId); return(permissions.Select(p => BusinessMapper.Map <PermissionModel>(p.Permission))); }
public async Task <UserModel> GetUserById(Guid userId) { var user = await _userManager.Users.FirstOrDefaultAsync(x => x.Id == userId); return(BusinessMapper.Map <UserModel>(user)); }
public async Task <IncidentModel> GetById(Guid incidentId) { var incident = await _incidentRepository.GetById(incidentId); return(BusinessMapper.Map <IncidentModel>(incident)); }