示例#1
0
        public Response GetAll(BaseListQuery query)
        {
            try
            {
                var results       = _metadataRepository.GetAll(query);
                var totalItems    = 0;
                var numberOfPages = 0;
                try
                {
                    totalItems    = results.FirstOrDefault().TotalItems;
                    numberOfPages = results.FirstOrDefault().NumberOfPages;
                }
                catch { }

                var resultAsDto = Mapper.Map <List <MetaDataDTO> >(results);

                return(new Response
                {
                    Data = new PagingDTO <MetaDataDTO>(resultAsDto, query, UrlHelper.Action("GetAll", "Metadata", query), numberOfPages, totalItems)
                });
            }
            catch (Exception e)
            {
                return(null);
            }
        }
示例#2
0
        public Response GetAllMediaTypes(BaseListQuery query)
        {
            try
            {
                var categories = _mediaTypeRepository.GetAll(query);
                var results    = Mapper.Map <List <MediaTypeDTO> >(categories);

                var totalItems    = 0;
                var numberOfPages = 0;

                try
                {
                    totalItems    = categories.FirstOrDefault().TotalItems;
                    numberOfPages = categories.FirstOrDefault().NumberOfPages;
                }
                catch { }

                return(new Response
                {
                    Data = new PagingDTO <MediaTypeDTO>(results, query, UrlHelper.Action("GetAllMediaTypes", "MediaType", query), numberOfPages, totalItems)
                });
            }
            catch (Exception e)
            {
                return(null);
            }
        }
示例#3
0
 public StatusRepositoryTest()
 {
     QueryWithDefaultValues = BaseListQuery.DefaultValues("nb");
     Mock             = new Mock.Mock();
     StatusRepository = new Repositories.StatusRepository(Mock.Database.Context);
     _status          = Mock.MockStatus();
 }
示例#4
0
        public List <Status> GetAll(BaseListQuery query)
        {
            var allStatus = _context.Status
                            .Include(x => x.Language)
                            .Include(x => x.TypeGroup)
                            .Where(x => x.Language.Abbreviation.Equals(query.Language));

            var totalItems = allStatus.Count();
            var totalPages = Convert.ToInt32(Math.Ceiling(totalItems * 1.0 / query.PageSize));

            if (query.Page > totalPages)
            {
                query.Page = 1;
            }

            var status = allStatus
                         .OrderBy(x => x.Id)
                         .Skip(query.PageSize * (query.Page - 1))
                         .Take(query.PageSize)
                         .ToList();

            status.ForEach(x =>
            {
                x.TotalItems    = totalItems;
                x.NumberOfPages = totalPages;
            });

            return(status);
        }
示例#5
0
        public Response GetAllStatus(BaseListQuery query)
        {
            try
            {
                var status = _statusRepository.GetAll(query);

                var totalItems    = 0;
                var numberOfPages = 0;

                try
                {
                    totalItems    = status.FirstOrDefault().TotalItems;
                    numberOfPages = status.FirstOrDefault().NumberOfPages;
                }
                catch { }

                return(new Response
                {
                    Data = new PagingDTO <StatusDTO>(
                        Mapper.Map <List <StatusDTO> >(status),
                        query,
                        UrlHelper.Action("GetAllStatus", "Status", query),
                        numberOfPages,
                        totalItems)
                });
            }
            catch
            {
                return(null);
            }
        }
示例#6
0
        public Response GetAllConcepts(BaseListQuery query)
        {
            try
            {
                var concepts      = _conceptRepository.GetAll(query);
                var totalItems    = 0;
                var numberOfPages = 0;

                try
                {
                    totalItems    = concepts.FirstOrDefault().TotalItems;
                    numberOfPages = concepts.FirstOrDefault().NumberOfPages;
                }
                catch { }

                var res = new PagingDTO <ConceptDto>(
                    Mapper.Map <List <ConceptDto> >(concepts),
                    query,
                    UrlHelper.Action("GetAll", "Concept", query),
                    numberOfPages,
                    totalItems);

                return(new Response
                {
                    Data = res
                });
            }
            catch (Exception e)
            {
                return(null);
            }
        }
示例#7
0
        public List <MetaCategory> GetAll(BaseListQuery query)
        {
            var allCategories = TableWithAllNestedObjects()
                                .Where(x => x.Language.Abbreviation.Equals(query.Language));

            var totalItems = allCategories.Count();
            var totalPages = Convert.ToInt32(Math.Ceiling(totalItems * 1.0 / query.PageSize));

            if (query.Page > totalPages)
            {
                query.Page = 1;
            }

            var categories = allCategories
                             .OrderBy(x => x.Id)
                             .Skip(query.PageSize * (query.Page - 1))
                             .Take(query.PageSize)
                             .ToList();

            categories.ForEach(x =>
            {
                x.TotalItems    = totalItems;
                x.NumberOfPages = totalPages;
            });


            return(categories);
        }
示例#8
0
        public List <MetaData> GetAll(BaseListQuery query)
        {
            var metadataWithQueriedLanguage = TableWithAllNestedObjects()
                                              .Where(a => a.Language.Abbreviation.Equals(query.Language))
                                              .ToList();
            var allMetaData = metadataWithQueriedLanguage;
            var totalItems  = allMetaData.Count();
            var totalPages  = Convert.ToInt32(Math.Ceiling(totalItems * 1.0 / query.PageSize));

            if (query.Page > totalPages)
            {
                query.Page = 1;
            }

            var meta = allMetaData
                       .OrderBy(x => x.Id)
                       .Skip(query.PageSize * (query.Page - 1))
                       .Take(query.PageSize)
                       .ToList();

            meta.ForEach(x =>
            {
                x.TotalItems    = totalItems;
                x.NumberOfPages = totalPages;
                x.Category      = _context.Categories.Include(y => y.TypeGroup).FirstOrDefault(y => y.Id == x.CategoryId);
            });

            return(meta);
        }
示例#9
0
        public List <MediaType> GetAll(BaseListQuery query)
        {
            var mediaTypes = _context.MediaTypes
                             .Include(x => x.Language)
                             .Include(x => x.TypeGroup)
                             .Where(x => x.Language.Abbreviation.Equals(query.Language));

            var totalItems = mediaTypes.Count();
            var totalPages = Convert.ToInt32(Math.Ceiling(totalItems * 1.0 / query.PageSize));

            if (query.Page > totalPages)
            {
                query.Page = 1;
            }

            var data = mediaTypes
                       .Skip(query.PageSize * (query.Page - 1))
                       .Take(query.PageSize)
                       .ToList();

            data.ForEach(x =>
            {
                x.TotalItems    = totalItems;
                x.NumberOfPages = totalPages;
            });

            return(data);
        }
示例#10
0
 public CategoryRepositoryTest()
 {
     _queryWithDefaultValues = BaseListQuery.DefaultValues("nb");
     Mock = new Mock.Mock();
     CategoryRepository = new Repositories.CategoryRepository(Mock.Database.Context);
     _category          = Mock.MockCategory();
     _language          = "nb";
 }
示例#11
0
        public void GetAll_Returns_Status_200_Categories_Is_Found()
        {
            A.CallTo(() => _service.GetAllCategories(A <BaseListQuery> ._)).Returns(_listResponse);

            var result   = _controller.GetAllCategories(BaseListQuery.DefaultValues("nb"));
            var okResult = result.Result as OkObjectResult;

            Assert.Equal(200, okResult.StatusCode);
        }
示例#12
0
        public void GetAll_Returns_A_List_Of_Categories_If_There_Exists_Categories()
        {
            A.CallTo(() => _service.GetAllCategories(A <BaseListQuery> ._)).Returns(_listResponse);

            var result   = _controller.GetAllCategories(BaseListQuery.DefaultValues("nb"));
            var okResult = result.Result as OkObjectResult;

            Assert.IsType <List <MetaCategory> >((okResult.Value as Response).Data);
        }
示例#13
0
        public void GetAll_Returns_Status_500_When_Service_Returns_Null()
        {
            A.CallTo(() => _service.GetAllCategories(A <BaseListQuery> ._)).Returns(null);

            var result = _controller.GetAllCategories(BaseListQuery.DefaultValues("nb"));
            var status = result.Result as StatusCodeResult;

            Assert.Equal((int)HttpStatusCode.InternalServerError, status.StatusCode);
        }
示例#14
0
        public BaseTest()
        {
            Mock = new Mock.Mock();
            var config         = Options.Create(ConfigHelper.GetDatabaseConfiguration());
            var languageConfig = Options.Create(ConfigHelper.GetLanguageConfiguration());

            ConceptRepository = new Repositories.ConceptRepository(Mock.Database.Context, config, languageConfig);
            BaseListQuery     = BaseListQuery.DefaultValues("en");
        }
示例#15
0
        public void GetRequiredCategories_Returns_EmptyList_If_No_Required_Categories_Exists()
        {
            Assert.Empty(CategoryRepository.GetAll(BaseListQuery.DefaultValues(_language)));
            var notRequiredCategory = Mock.MockCategory();

            notRequiredCategory.IsRequired = false;
            Mock.Database.InsertCategory(notRequiredCategory);

            Assert.Empty(CategoryRepository.GetRequiredCategories(_language));
        }
示例#16
0
        public ActionResult <Response> GetAllStatus([FromQuery] BaseListQuery query)
        {
            var status = _service.GetAllStatus(query);

            if (status != null)
            {
                return(Ok(status));
            }

            return(InternalServerError());
        }
示例#17
0
        public ActionResult <Response> GetAll([FromQuery] BaseListQuery query)
        {
            var meta = _service.GetAll(query);

            if (meta != null)
            {
                return(Ok(meta));
            }

            return(InternalServerError());
        }
示例#18
0
        public ActionResult <Response> GetAll(BaseListQuery query)
        {
            var concepts = _service.GetAllConcepts(query);

            if (concepts != null)
            {
                return(Ok(concepts));
            }

            return(InternalServerError());
        }
示例#19
0
        public ActionResult <Response> GetAllCategories([FromQuery] BaseListQuery query)
        {
            var categories = _service.GetAllCategories(query);

            if (categories != null)
            {
                return(Ok(categories));
            }

            return(InternalServerError());
        }
示例#20
0
 public MetadataControllerTest()
 {
     _service      = A.Fake <IMetadataService>();
     _controller   = new MetadataController(_service);
     _listResponse = new Response {
         Data = new List <MetaData>()
     };
     _singleResponse = new Response {
         Data = new MetaData()
     };
     _queryWithDefaultValues = BaseListQuery.DefaultValues("nb");
 }
示例#21
0
        public MetaDataRepositoryTest()
        {
            _queryWithDefaultValues = BaseListQuery.DefaultValues("nb");
            var config = ConfigHelper.GetLanguageConfiguration();

            Mock           = new Mock.Mock();
            MetaRepository = new Repositories.MetadataRepository(Mock.Database.Context, new OptionsWrapper <LanguageConfig>(config));


            _status   = Mock.Database.InsertStatus(Mock.MockStatus());
            _category = Mock.Database.InsertCategory(Mock.MockCategory());
        }
示例#22
0
        public PagingDTO(List <T> results, BaseListQuery query, string next, int pages = 1, int totalItems = 0)
        {
            PageSize      = query.PageSize;
            Page          = query.Page;
            TotalItems    = totalItems;
            NumberOfPages = pages;
            Results       = results;

            if (Page < NumberOfPages)
            {
                query.Page += 1;
                Next        = next;
            }
        }
示例#23
0
        public void GetRequiredCategories_Returns_List_Of_Categories_When_Some_Exists()
        {
            Assert.Empty(CategoryRepository.GetAll(BaseListQuery.DefaultValues(_language)));
            var notRequiredCategory = Mock.MockCategory();

            notRequiredCategory.IsRequired = false;

            var requiredCategory = Mock.MockCategory();

            requiredCategory.IsRequired = true;
            Mock.Database.InsertCategory(requiredCategory);

            Assert.Single(CategoryRepository.GetRequiredCategories(_language));
        }
示例#24
0
        public ConceptControllerTest()
        {
            _tokenHelper = A.Fake <ITokenHelper>();
            A.CallTo(() => _tokenHelper.ReturnScope(A <ClaimsPrincipal> ._)).Returns(_allowedScope);
            A.CallTo(() => _tokenHelper.GetUserInfo()).Returns(new UserInfo());

            _service       = A.Fake <IConceptService>();
            _controller    = new ConceptController(_service, _tokenHelper);
            _createConcept = new CreateConceptDto
            {
                Title   = "Title",
                Content = "Content",
                Created = DateTime.Now,
                Updated = DateTime.Now,
            };
            _updateConcept = new UpdateConceptDto
            {
                Title   = "Title",
                Content = "Content",
                Created = DateTime.Now,
                Updated = DateTime.Now,
            };

            _searchQuery = new ConceptSearchQuery {
                Title = "title", MetaIds = new List <int> {
                    1, 2
                }
            };

            _errorResponse = new Response
            {
                Errors = new ModelStateDictionary()
            };
            _errorResponse.Errors.TryAddModelError("err", "err");

            _listResponse = new Response {
                Data = new List <ConceptDto>()
            };
            _singleResponse = new Response {
                Data = new ConceptDto()
            };
            _userInfo = new UserInfo
            {
                Email    = _allowedUserEmail,
                FullName = "Name"
            };

            _listQuery = BaseListQuery.DefaultValues(language);
        }
示例#25
0
        public List <MetaData> SearchForMetadata(MetaSearchQuery searchArgument)
        {
            var query = TableWithAllNestedObjects()
                        .AsQueryable();

            if (searchArgument == null || searchArgument.HasNoQuery())
            {
                return(GetAll(BaseListQuery.DefaultValues(_languageConfig.Default)));
            }

            var searchArgsHasName     = !string.IsNullOrWhiteSpace(searchArgument.Name);
            var searchArgsHasCategory = !string.IsNullOrWhiteSpace(searchArgument.Category);

            if (searchArgsHasCategory)
            {
                query = query.Where(x => x.Category.Name.ToLower().Equals(searchArgument.Category.ToLower()));
            }

            if (searchArgsHasName)
            {
                query = query.Where(x => x.Name.ToLower().Contains(searchArgument.Name.ToLower()));
            }

            var totalItems = query.Count();
            var totalPages = Convert.ToInt32(Math.Ceiling(totalItems * 1.0 / searchArgument.PageSize));

            if (searchArgument.Page > totalPages)
            {
                searchArgument.Page = 1;
            }

            var offset = searchArgument.PageSize * (searchArgument.Page - 1);

            var meta = query
                       .OrderBy(x => x.Id)
                       .Skip(offset)
                       .Take(searchArgument.PageSize)
                       .ToList();

            meta.ForEach(x =>
            {
                x.TotalItems    = totalItems;
                x.NumberOfPages = totalPages;
            });

            return(meta);
        }
示例#26
0
        public List <Concept> SearchForConcepts(ConceptSearchQuery searchParam)
        {
            if (searchParam == null)
            {
                return(GetAll(BaseListQuery.DefaultValues(_languageConfig.Default)));
            }

            var queryHasTitle   = !string.IsNullOrWhiteSpace(searchParam.Title);
            var queryHasMetaIds = searchParam.MetaIds != null &&
                                  searchParam.MetaIds.Count > 0;
            var sqlParameters = searchParam.GetSqlParameters();

            if (queryHasTitle && !queryHasMetaIds)
            {
                return(GetConceptsByStoredProcedure("get_concepts_by_title", sqlParameters));
            }

            if (!queryHasTitle && queryHasMetaIds)
            {
                return(GetConceptsByStoredProcedure("get_concepts_by_list_of_meta_id", sqlParameters));
            }

            if (!queryHasMetaIds && !queryHasTitle)
            {
                if (string.IsNullOrEmpty(searchParam.Language))
                {
                    searchParam.Language = _languageConfig.Default;
                }
                return(GetAll(searchParam));
            }

            // Has metaIds and title
            var result = GetConceptsByStoredProcedure("get_concepts_by_title_and_meta_id", sqlParameters);

            // Did not find any results with metaIds. Tries with title only
            if (result == null || result.Count == 0)
            {
                sqlParameters.ForEach(x => x.Collection = null);
                sqlParameters.RemoveAll(x => x.ParameterName == "list_of_meta_id");
                return(GetConceptsByStoredProcedure("get_concepts_by_title", sqlParameters));
            }
            return(result);
        }
示例#27
0
        public List <int> MediaTypesNotExistInDatabase(List <MediaWithMediaType> mediaTypes, string language)
        {
            var noExistingIds = new List <int>();

            if (mediaTypes == null)
            {
                return(noExistingIds);
            }

            var allMediaTypes = _mediaTypeRepository.GetAll(BaseListQuery.DefaultValues(language));
            var pages         = 1;

            try
            {
                pages = allMediaTypes.FirstOrDefault().NumberOfPages;
            }
            catch { }

            for (var page = 0; page < pages; page++)
            {
                var query = BaseListQuery.DefaultValues(language);
                query.Page = page + 1;
                var medias = _mediaTypeRepository
                             .GetAll(query)
                             .Select(x => x.Id)
                             .ToList();
                foreach (var mediaType in mediaTypes)
                {
                    if (!medias.Contains(mediaType.MediaTypeId))
                    {
                        noExistingIds.Add(mediaType.MediaTypeId);
                    }
                }
            }


            return(noExistingIds);
        }
示例#28
0
        public ConceptServiceTest()
        {
            ConceptMediaRepository = A.Fake <IConceptMediaRepository>();
            ConceptRepository      = A.Fake <IConceptRepository>();
            StatusRepository       = A.Fake <IStatusRepository>();
            LanguageRepository     = A.Fake <ILanguageRepository>();
            MetadataRepository     = A.Fake <IMetadataRepository>();
            UrlHelper = A.Fake <IUrlHelper>();

            Mapper = AutoMapper.Mapper.Instance;

            Service                 = new ConceptService(ConceptRepository, StatusRepository, ConceptMediaRepository, MetadataRepository, LanguageRepository, Mapper, UrlHelper);
            Mock                    = new Mock.Mock();
            _status                 = new Status();
            BaseListQuery           = BaseListQuery.DefaultValues("nb");
            _language               = new Language();
            _listOfMetaWithLanguage = new List <MetaData> {
                new MetaData
                {
                    Language = _language, Category = new MetaCategory {
                        TypeGroup = new TypeGroup {
                            Name = "language"
                        }
                    }
                }
            };
            _userInfo = new UserInfo
            {
                FullName = "Fullname",
                Email    = "Email"
            };

            A.CallTo(() => StatusRepository.GetById(A <int> ._)).Returns(null);
            A.CallTo(() => MetadataRepository.GetByRangeOfIds(A <List <int> > ._)).Returns(_listOfMetaWithLanguage);
            A.CallTo(() => LanguageRepository.GetByAbbreviation(A <string> ._)).Returns(_language);
        }
示例#29
0
        public List <Concept> GetAll(BaseListQuery query)
        {
            var sqlParameters = new List <NpgsqlParameter>
            {
                new NpgsqlParameter("number_of_record_to_show", NpgsqlDbType.Integer)
                {
                    Value = query.PageSize
                },
                new NpgsqlParameter("page_number", NpgsqlDbType.Integer)
                {
                    Value = query.Page
                },
                new NpgsqlParameter("language_param", NpgsqlDbType.Varchar)
                {
                    Value = query.Language
                },
                new NpgsqlParameter("default_language_param", NpgsqlDbType.Varchar)
                {
                    Value = _languageConfig.Default
                }
            };

            return(GetConceptsByStoredProcedure("get_concepts", sqlParameters));
        }