public async Task <IEnumerable <StudyDirection> > Get(StudyDirectionGetOptions options) { try { StringBuilder sql = new StringBuilder(); _logger.LogInformation("Try to create get study directions sql query"); sql.AppendLine(@" select Id, DepartmentId, Code, Name, ShortName from StudyDirection"); int conditionIndex = 0; if (options.Id.HasValue) { sql.AppendLine($"{(conditionIndex++ == 0 ? "where" : "and")} Id = @id"); } if (options.DepartmentId.HasValue) { sql.AppendLine($"{(conditionIndex++ == 0 ? "where" : "and")} DepartmentId = @DepartmentId"); } if (options.Ids != null && options.Ids.Count > 0) { sql.AppendLine($"{(conditionIndex++ == 0 ? "where" : "and")} Id = any(@ids)"); } if (options.DepartmentIds != null && options.DepartmentIds.Count > 0) { sql.AppendLine($"{(conditionIndex++ == 0 ? "where" : "and")} (DepartmentId in @DepartmentIds)"); } if (options.Names != null && options.Names.Count > 0) { sql.AppendLine($"{(conditionIndex++ == 0 ? "where" : "and")} (Name in @Names)"); } _logger.LogInformation($"Sql query successfully created:\n{sql.ToString()}"); _logger.LogInformation("Try to execute sql get study directions query"); var result = await QueryAsync <StudyDirection>(sql.ToString(), options); _logger.LogInformation("Sql get study directions query successfully executed"); return(result); } catch (Exception exception) { _logger.LogError(exception.Message); throw exception; } }
public async Task <IEnumerable <StudyDirection> > Get(StudyDirectionGetOptions options) { return(await _dao.Get(options)); }