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));
            }
        }
예제 #2
0
        public void GetByUserComponentTypeId_WhenIdIsNull_ShouldReturnEmptyCollection()
        {
            var result = _userComponentTypeDetailService.GetByUserComponentTypeId(null);

            Assert.IsTrue(!result.Any());
        }