Пример #1
0
        public YeastViewModel CreateYeastViewModel()
        {
            var model = new YeastViewModel();

            model.Brands.AddRange(CreateSelectList("Brand", _yeastBrandsDtoList));
            model.Styles.AddRange(CreateSelectList("Style", _yeastStylesDtoList));
            return(model);
        }
Пример #2
0
        public YeastPairingViewModel CreateYeastPairingViewModel(YeastPairDto pairingDto)
        {
            if (pairingDto == null)
            {
                throw new ArgumentNullException(nameof(pairingDto));
            }

            var yeastDto       = _yeastsDtoList.FirstOrDefault(y => y.Id == pairingDto.Yeast.Value);
            var yeastViewModel = new YeastViewModel
            {
                Id        = yeastDto.Id,
                Brand     = CreateYeastBrandViewModel(yeastDto.Brand),
                Style     = CreateYeastStyleViewModel(yeastDto.Style),
                Trademark = yeastDto.Trademark,
                TempMax   = yeastDto.TempMax,
                TempMin   = yeastDto.TempMin,
                Alcohol   = yeastDto.Alcohol,
                Note      = yeastDto.Note
            };
            var yeastModel = yeastViewModel;

            var categoryModel = new CategoryViewModel();

            if (pairingDto.Category.HasValue)
            {
                var categoryDto = _categoriesDtoList.FirstOrDefault(c => c.Id == pairingDto.Category.Value);
                if (categoryDto != null)
                {
                    categoryModel = CreateCategoryViewModel(categoryDto);
                }
            }

            var varietyModel = new VarietyViewModel();

            if (pairingDto.Variety.HasValue)
            {
                var varietyDto = _varietiesDtoList.FirstOrDefault(v => v.Id == pairingDto.Variety.Value);
                varietyModel = CreateVarietyViewModel(varietyDto, null);
            }

            var existingPairings = _yeastPairingsDtoList.Where(p => p.Yeast.Value == yeastModel.Id && p.Id != pairingDto.Id).ToList();
            var model            = new YeastPairingViewModel
            {
                Id       = pairingDto.Id,
                Yeast    = yeastModel,
                Category = categoryModel,
                Variety  = varietyModel,
                Note     = pairingDto.Note
            };

            model.Varieties.AddRange(CreateSelectList("Variety", _varietiesDtoList, _categoriesDtoList, existingPairings));

            return(model);
        }
Пример #3
0
        public YeastViewModel CreateYeastViewModel(YeastDto yeastDto)
        {
            if (yeastDto == null)
            {
                throw new ArgumentNullException(nameof(yeastDto));
            }

            var model = new YeastViewModel
            {
                Id        = yeastDto.Id,
                Brand     = CreateYeastBrandViewModel(yeastDto.Brand),
                Style     = CreateYeastStyleViewModel(yeastDto.Style),
                Trademark = yeastDto.Trademark,
                TempMax   = yeastDto.TempMax,
                TempMin   = yeastDto.TempMin,
                Alcohol   = yeastDto.Alcohol,
                Note      = yeastDto.Note
            };

            model.Brands.AddRange(CreateSelectList("Brand", _yeastBrandsDtoList));
            model.Styles.AddRange(CreateSelectList("Style", _yeastStylesDtoList));

            var dto = new YeastPairDto {
                Yeast = yeastDto.Id
            };

            model.Pairing          = CreateYeastPairingViewModel(dto);
            model.Pairing.Category = null;
            model.Pairing.Variety  = null;

            var pairs = _yeastPairingsDtoList.Where(p => p.Yeast.Value == yeastDto.Id).ToList();

            if (pairs != null)
            {
                model.Pairings.Clear();
                model.Pairings.AddRange(CreateYeastPairingViewModel(pairs));
            }

            return(model);
        }