コード例 #1
0
        public async Task <IEnumerable <DisciplineTitle> > GetNotPinnedDisciplines(DisciplineTitleGetOptions options)
        {
            var models = await _dao.Get(options);

            var resultModels = models.GroupBy(o => o.Id).Select(o => o.First()).ToList();
            var allTypes     = Enum.GetValues(typeof(ProjectType)).Cast <ProjectType>().ToList();

            foreach (var model in resultModels)
            {
                var pinnedProjectTypes = models.Where(o => o.Id == model.Id).Select(o => o.PinnedProjectType);
                model.NotPinnedProjectTypes = allTypes.Where(o => !pinnedProjectTypes.Contains(o)).ToList();
            }

            return(resultModels);
        }
コード例 #2
0
        public async Task <IEnumerable <DisciplineTitle> > Get(DisciplineTitleGetOptions options)
        {
            try
            {
                StringBuilder sql = new StringBuilder();

                _logger.LogInformation("Try to create get discipline titles sql query");

                sql.AppendLine(@"
                    select 
                        distinct
                        dt.Id,
                        dt.Name,
                        dt.Shortname,
                        dt.DepartmentId,
                        pd.ProjectType as PinnedProjectType,
	                    case
	                        when pd.Id is null then 0
	                        else 1
	                    end as Pinned
                    from DisciplineTitle dt
                    left join PinnedDiscipline pd on pd.DisciplineTitleId = dt.Id
                    left join GroupDisciplineLoad gdl on gdl.DisciplineTitleId = dt.Id
                ");

                int conditionIndex = 0;
                if (options.Id.HasValue)
                {
                    sql.AppendLine($"{(conditionIndex++ == 0 ? "where" : "and")} pd.Id = @id");
                }

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

                if (options.NotPinned.HasValue)
                {
                    sql.AppendLine($"{(conditionIndex++ == 0 ? "where" : "and")} pd.Id is null");
                }

                if (options.Ids != null && options.Ids.Count > 0)
                {
                    sql.AppendLine($"{(conditionIndex++ == 0 ? "where" : "and")} pd.Id in @Ids");
                }

                if (options.DepartmentIds != null && options.DepartmentIds.Count > 0)
                {
                    sql.AppendLine($"{(conditionIndex++ == 0 ? "where" : "and")} dt.DepartmentId in @DepartmentIds");
                }

                if (options.Titles != null && options.Titles.Count > 0)
                {
                    sql.AppendLine($"{(conditionIndex++ == 0 ? "where" : "and")} dt.Name in @Titles");
                }

                if (options.DepartmentLoadsIds != null && options.DepartmentLoadsIds.Count > 0)
                {
                    sql.AppendLine($"{(conditionIndex++ == 0 ? "where" : "and")} gdl.DepartmentLoadId in @DepartmentLoadsIds");
                }

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

                _logger.LogInformation("Try to execute sql get disciplines titles query");
                var result = await QueryAsync <DisciplineTitle>(sql.ToString(), options);

                _logger.LogInformation("Sql get disciplines titles query successfully executed");
                return(result);
            }
            catch (Exception exception)
            {
                _logger.LogError(exception.Message);
                throw exception;
            }
        }
コード例 #3
0
 public async Task <IEnumerable <DisciplineTitle> > Get(DisciplineTitleGetOptions options)
 {
     return(await _dao.Get(options));
 }
コード例 #4
0
        public async Task <IActionResult> Get([FromQuery] DisciplineTitleGetOptions options)
        {
            var models = await _disciplineService.GetNotPinnedDisciplines(options);

            return(Ok(models));
        }