public void GetAll_WhenCalled_ShouldntReturnNull()
        {
            var result = _staticSiteInfoService.GetAll();

            Assert.IsNotNull(result);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Index()
        {
            var users          = _mapper.Map <IEnumerable <UserViewModel> >(_userManager.Users);
            var administrators = await _userManager.GetUsersInRoleAsync(AppUserRoles.Administrator);

            var administratorsIds = administrators.Select(x => x.Id).ToList();

            var componentTypes      = _componentTypeService.GetAll();
            var componentTypeModels = _mapper.Map <IEnumerable <ComponentTypeViewModel> >(componentTypes);
            var unitMultipliers     = _mapper.Map <IEnumerable <UnitMultiplierViewModel> >(_unitMultiplierService.GetAll());
            var staticSiteInfos     = _mapper.Map <IEnumerable <StaticSiteInfoViewModel> >(_staticSiteInfoService.GetAll());

            foreach (var user in users)
            {
                user.IsAdmin = administratorsIds.Contains(user.Id);
            }

            foreach (var componentTypeModel in componentTypeModels)
            {
                var imageId = componentTypes.SingleOrDefault(x => x.Id == componentTypeModel.Id)?.ImageId;
                componentTypeModel.ImageUrl = $"{Constants.BaseImageUrl}{imageId}";
            }

            foreach (var info in staticSiteInfos)
            {
                info.Content = info.Content.Length > 100 ? $"{info.Content.Substring(0, 100)}...." : info.Content;
            }

            var model = new IndexViewModel
            {
                Users           = users,
                ComponentTypes  = componentTypeModels,
                UnitMultipliers = unitMultipliers,
                StaticSiteInfos = staticSiteInfos
            };

            return(View(model));
        }