Esempio n. 1
0
        public async Task <IEnumerable <UserLoad> > Get(UserLoadGetOptions options)
        {
            try
            {
                StringBuilder sql = new StringBuilder();

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

                sql.AppendLine(@"
                    select
                        ul.Id,
                        ul.UserId,
                        ul.StudyLoadId,
                        ul.StudentsCount
                    from UserLoad ul
                ");

                int conditionIndex = 0;

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

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

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

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

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

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

                _logger.LogInformation("Sql get study load query successfully executed");
                return(result);
            }
            catch (Exception exception)
            {
                _logger.LogError(exception.Message);
                throw exception;
            }
        }
Esempio n. 2
0
        public async Task <IEnumerable <UserLoad> > Get(UserLoadGetOptions options)
        {
            var userLoad = await _dao.Get(options);

            var users = await _userService.Get(new UserGetOptions
            {
                Ids = userLoad.Select(o => o.UserId).ToList()
            });

            foreach (var load in userLoad)
            {
                load.User = users.FirstOrDefault(o => o.Id == load.UserId);
            }

            return(userLoad);
        }