public async Task <IActionResult> MyComponent(int?userComponentTypeId, int?defaultComponentTypeId)
        {
            var componentTypes = _componentTypeService.GetAll()
                                 .Include(x => x.Details)
                                 .Where(x => x.Details.Count(s => s.IsPrimary) > 0)
                                 .ToList();

            var multipliers = _unitMultiplierService.GetAll();

            var userComponent = await _userComponentTypeService.GetByIdAsync(userComponentTypeId);

            if (userComponent == null)
            {
                var defaultModel = new MyComponentInputModel
                {
                    ComponentTypes  = componentTypes,
                    ComponentTypeId = defaultComponentTypeId ?? 0
                };

                return(View(defaultModel));
            }
            else
            {
                var details      = _userComponentTypeDetailService.GetByUserComponentTypeId(userComponent.Id);
                var inputDetails = details.Select(x => new MyComponentDetailInputModel
                {
                    DetailId     = x.Id,
                    Name         = x.ComponentTypeDetail.Name,
                    MultiplierId = x.UnitMultiplierId,
                    Unit         = x.ComponentTypeDetail.Unit,
                    Value        = x.Value
                }).ToList();

                var model = new MyComponentInputModel
                {
                    Id = userComponent.Id,
                    ComponentTypeId = userComponent.ComponentTypeId,
                    Quantity        = userComponent.Quantity,
                    UnitPrice       = userComponent.UnitPrice,
                    ComponentTypes  = componentTypes,
                    UnitMultipliers = multipliers,
                    Details         = inputDetails
                };

                return(View(model));
            }
        }
Esempio n. 2
0
        private IEnumerable <ComponentTypeVM> BuildComponentTypeSearchQuery(params string[] words)
        {
            IEnumerable <ComponentTypeDTO> componentTypeDTOs = ComponentTypeService.GetAll()
                                                               .ToList()
                                                               .Where(d => words.All(d.Name.ToLower().Contains));

            IEnumerable <ComponentTypeVM> componentTypeVMs = Mapper.Map <IEnumerable <ComponentTypeVM> >(componentTypeDTOs);

            return(componentTypeVMs);
        }
Esempio n. 3
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));
        }
Esempio n. 4
0
 public SelectList GetComponentTypeIdSelectList(Guid?selectedValue = null)
 {
     return(new SelectList(ComponentTypeService.GetAll(), "Id", "Name", selectedValue));
 }
 public ActionResult Get()
 {
     return(Ok(
                componentTypeService.GetAll()
                ));
 }
Esempio n. 6
0
 public IQueryable <ComponentType> GetAllComponentTypes()
 {
     return(_componentTypeService
            .GetAll());
 }
Esempio n. 7
0
        public void GetAll_WhenCalled_ShouldntReturnNull()
        {
            var result = _componentTypeService.GetAll();

            Assert.IsNotNull(result);
        }