public async Task OnGet() { var page = "0"; if (!Request.Query["page"].Equals("")) { page = Request.Query["page"]; } var perPage = "15"; if (!Request.Query["perPage"].Equals("")) { perPage = Request.Query["page"]; } var spec = ""; if (!Request.Query["spec"].Equals(String.Empty)) { spec = Request.Query["page"]; } var q = new ListDoctorsDto() { Page = PageQ, PerPage = PerPage, Specialization = Specialization }; DoctorsResponse = await _doctorService.List(q); Page(); }
public async Task <Pageable <DoctorResponse> > Read(ListDoctorsDto args) { var doctors = new List <DoctorResponse>(); var result = new Pageable <DoctorResponse> { Items = doctors, Total = 0 }; var sql = ListDoctorQuery; var whereQ = "WHERE 1 = 1"; if (!args.Specialization.Equals(string.Empty)) { whereQ += "AND specialization = @spec"; } sql += whereQ; sql += $"limit {args.PerPage} offset {args.PerPage * args.Page}"; await using var query = new NpgsqlCommand(sql, Conn); if (!args.Specialization.Equals(string.Empty)) { query.Parameters.AddWithValue("spec", args.Specialization); } await using var reader = await query.ExecuteReaderAsync(); try { while (await reader.ReadAsync()) { doctors.Add(MapToDoctorResp(reader)); } } catch (Exception e) { Console.WriteLine(e); throw; } var countSql = CountDoctorQuery; if (!args.Specialization.Equals(string.Empty)) { countSql += "where specialization = @spec"; } await query.DisposeAsync(); await reader.CloseAsync(); await using var countQuery = new NpgsqlCommand(countSql, Conn); if (!args.Specialization.Equals(string.Empty)) { countQuery.Parameters.AddWithValue("spec", args.Specialization); } var countReader = (long)await countQuery.ExecuteScalarAsync(); result.Total = countReader; return(result); }