Example #1
0
    public void GetFilteredValues()
    {
        // Arrange & Act
        var result = _filterService.FilterOut(GetCertificates(), "2017", "certificate1", Stage.District);

        // Assert
        Assert.Single(result);
    }
    public PublicViewModel GetPublicViewModel(int page, string year, string find, Stage?stage,
                                              ApplicationUser user)
    {
        page = page <= 0 ? 1 : page;

        var list = _cacheService.GetList(user.Id);

        list = _filterService.FilterOut(list, year, find, stage).ToList();

        var count = list.Count;

        var items = _pageService.GetDataToPage(list, count, ref page);

        var certificates = items.Select(i =>
        {
            var certificateViewModel = new CertificateViewModel
            {
                Id          = i.Id,
                Title       = i.Title,
                Description = i.Description,
                Date        = i.Date,
                Path        = i.Path,
                UserId      = i.UserId
            };
            return(certificateViewModel);
        });

        var years = EnumerableHelper.GetYears(_localizer["All"]);

        var stages = _stageService.GetStages(includeAllValue: true);

        PublicViewModel pvm = new()
        {
            Certificates = certificates,
            Find         = find,
            Stage        = null,
            Year         = year,
            Stages       = new SelectList(stages, "EnumName", "Name"),
            Years        = new SelectList(years),
            Name         = user.Name,
            Surname      = user.Surname,
            UniqueUrl    = user.UniqueUrl,
            MiddleName   = user.MiddleName,
            ImageData    = user.Photo,
            Controller   = "Public",
            Parameters   = new Dictionary <string, string>
            {
                ["uniqueUrl"] = user.UniqueUrl
            },
            PageViewModel = new PageViewModel(count, page, Common.PageSize)
        };

        return(pvm);
    }
    public IndexViewModel GetIndexViewModel(int page, string userId, string year, string find, Stage?stage)
    {
        page = page <= 0 ? 1 : page;

        var list = _repository.ListByUserId(userId);

        list = _filterService.FilterOut(list, year, find, stage);

        var count = list.Count();

        var items = _pageService.GetDataToPage(list, count, ref page, includeCheck: true);

        var certificates = items.Select(i =>
        {
            var certificateViewModel = new CertificateViewModel
            {
                Id          = i.Id,
                Title       = i.Title,
                Description = i.Description,
                Date        = i.Date,
                Path        = i.Path
            };

            return(certificateViewModel);
        });

        var years = EnumerableHelper.GetYears(_localizer["All"]);

        var stages = _stageService.GetStages(includeAllValue: true);

        IndexViewModel ivm = new IndexViewModel
        {
            Certificates  = certificates,
            Find          = find,
            Year          = year,
            Stage         = null,
            Years         = new SelectList(years),
            Stages        = new SelectList(stages, "EnumName", "Name"),
            Controller    = "Certificate",
            PageViewModel = new PageViewModel(count, page, Common.PageSize)
        };

        return(ivm);
    }