Example #1
0
        public async Task <IEnumerable <DepartmentLoad> > Get(DepartmentLoadGetOptions options)
        {
            try
            {
                StringBuilder sql = new StringBuilder();

                _logger.LogInformation("Try to create get department loads sql query");

                sql.AppendLine(@"
                    select 
                        Id,
                        StudyYear,
                        DepartmentId,
                        Total
                    from DepartmentLoad
                ");

                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.DepartmentIds != null)
                {
                    sql.AppendLine($"{(conditionIndex++ == 0 ? "where" : "and")} DepartmentId in @DepartmentIds");
                }

                _logger.LogInformation($"Sql query successfully created:\n{sql.ToString()}");

                _logger.LogInformation("Try to execute sql get departments loads query");
                var result = await QueryAsync <DepartmentLoad>(sql.ToString(), options);

                _logger.LogInformation("Sql get departments loads query successfully executed");
                return(result);
            }
            catch (Exception exception)
            {
                _logger.LogError(exception.Message);
                throw exception;
            }
        }
        public async Task <IEnumerable <DepartmentLoad> > Get(DepartmentLoadGetOptions options)
        {
            var loads = await _dao.Get(options);

            var loadsIds = loads.Select(o => o.Id).ToList();

            var groupDisciplineLoad = await _groupDisciplineLoadService.Get(new GroupDisciplineLoadGetOptions
            {
                DepartmentLoadsIds = loadsIds
            });

            foreach (var load in loads)
            {
                load.GroupDisciplineLoad = groupDisciplineLoad.Where(o => o.DepartmentLoadId == load.Id).ToList();
            }

            return(loads);
        }
 public async Task <IActionResult> Get([FromQuery] DepartmentLoadGetOptions options)
 {
     return(Ok(await _service.Get(options)));
 }