Beispiel #1
0
        public async Task <IEnumerable <StudyLoad> > Get(StudyLoadGetOptions options)
        {
            try
            {
                StringBuilder sql = new StringBuilder();

                _logger.LogInformation("Try to create get study load sql query");

                sql.AppendLine(@"
                    select
                        sl.Id,
                        sl.GroupDisciplineLoadId,
                        sl.ShownValue,
                        sl.Value,
                        sl.ProjectType
                    from StudyLoad sl
                    left join UserLoad ul on ul.StudyLoadId = sl.Id
                ");

                int conditionIndex = 0;

                if (options.GroupDisciplineLoadId.HasValue)
                {
                    sql.AppendLine($"{(conditionIndex++ == 0 ? "where" : "and")} (sl.GroupDisciplineLoadId = @GroupDisciplineLoadId)");
                }

                if (options.OnlyDistributed.HasValue)
                {
                    sql.AppendLine($"{(conditionIndex++ == 0 ? "where" : "and")} (ul.UserId is not null)");
                }

                if (options.OnlyNotDistibuted.HasValue)
                {
                    sql.AppendLine($"{(conditionIndex++ == 0 ? "where" : "and")} (ul.UserId is null)");
                }

                if (options.GroupDisciplineLoadsIds != null)
                {
                    sql.AppendLine($"{(conditionIndex++ == 0 ? "where" : "and")} (sl.GroupDisciplineLoadId in @GroupDisciplineLoadsIds)");
                }

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

                _logger.LogInformation("Try to execute sql get study load query");
                var result = await QueryAsync <StudyLoad>(sql.ToString(), options);

                _logger.LogInformation("Sql get study load query successfully executed");
                return(result);
            }
            catch (Exception exception)
            {
                _logger.LogError(exception.Message);
                throw exception;
            }
        }
Beispiel #2
0
        public async Task <IEnumerable <StudyLoad> > Get(StudyLoadGetOptions options)
        {
            var studyLoad = await _studyLoadDao.Get(options);

            var usersLoad = await _userLoadService.Get(new UserLoadGetOptions
            {
                StudyLoadsIds = studyLoad.Select(o => o.Id).ToList()
            });

            foreach (var load in studyLoad)
            {
                load.UsersLoad = usersLoad.Where(o => o.StudyLoadId == load.Id).ToList();
            }

            return(studyLoad);
        }