Пример #1
0
 public async Task OnGetAsync()
 {
     try
     {
         Students = await _repository.GetAllStudentsAsync();
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
        public async Task <ActionResult <StudentModel[]> > Get()
        {
            try
            {
                var results = await _repository.GetAllStudentsAsync();

                return(_mapper.Map <StudentModel[]>(results));
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Database failure"));
            }
        }
Пример #3
0
        public async Task <IActionResult> GetAllStudentsAsync()
        {
            try
            {
                var students = await _studentsRepository.GetAllStudentsAsync();

                if (students != null)
                {
                    return(new OkObjectResult(students.Select(p => new StudentViewModel
                    {
                        // Id = p.StudentId,
                        Gender = p.Gender.Trim(),
                        Name = p.Name.Trim(),
                        SchoolId = p.School
                    }
                                                              )));
                }
                return(new NotFoundResult());
            }
            catch
            {
                return(new ConflictResult());
            }
        }