public async Task <ObjectResponse <User> > LoginUserAsync(string email, string password, string signinIp) { UserDb user = await _ivySchoolRepository.GetAllActiveUsers().FirstOrDefaultAsync(e => e.Email == email && e.Password == password); if (user == null) { return(ObjectResponse <User> .Error("The user does not exist.")); } SigninHistoryDb signIn = new SigninHistoryDb() { SigninTime = DateTime.Now, SigninIp = signinIp, userId = user.UserId, }; try { await _ivySchoolRepository.AddSignIn(signIn); } catch (DBOperationException ex) { return(ObjectResponse <User> .Error(ex.Message)); } return(ObjectResponse <User> .Success(user.ToUser())); }
public async Task <ObjectResponse <IEnumerable <StudentUser> > > GetStudentList() { try { var students = (await _ivySchoolRepository.GetStudents().ToListAsync()).Select(ConvertToStudentUser); return(ObjectResponse <IEnumerable <StudentUser> > .Success(students)); } catch (DBOperationException ex) { return(ObjectResponse <IEnumerable <StudentUser> > .Error(ex.Message)); } }
public async Task <SimpleResponse> GetCourseDetail(int courseId) { try { var course = await _ivySchoolRepository.GetCourseById(courseId); return(ObjectResponse <CourseDetail> .Success(ConvertToCourseDetail(course))); } catch (DBOperationException ex) { return(SimpleResponse.Error(ex.Message)); } }
public async Task <ObjectResponse <StudentDetail> > GetStudentDetail(int studentId) { try { var student = await _ivySchoolRepository.GetStudents().FirstOrDefaultAsync(); return(ObjectResponse <StudentDetail> .Success(ConvertToStudentDetail(student))); } catch (DBOperationException ex) { return(ObjectResponse <StudentDetail> .Error(ex.Message)); } }
public async Task <ObjectResponse <IEnumerable <User> > > GetAdministrators() { try { var admins = await _ivySchoolRepository.GetAllActiveUsers() .Where(u => u.RoleUsers.Any(ru => ru.Role.Role == "Admin")) .Select(u => u.ToUser()) .ToListAsync(); return(ObjectResponse <IEnumerable <User> > .Success(admins)); } catch (Exception ex) { return(ObjectResponse <IEnumerable <User> > .Error(ex.Message)); } }