示例#1
0
        public VarietyViewModel CreateVarietyViewModel()
        {
            var model = new VarietyViewModel();

            model.Categories.AddRange(CreateSelectList("Parent Category", _categoriesDtoList));
            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 CategoryViewModel CreateCategoryViewModel(ICode categoryDto)
        {
            if (categoryDto == null)
            {
                throw new ArgumentNullException(nameof(categoryDto));
            }

            var model = new CategoryViewModel
            {
                Description = categoryDto.Description,
                Enabled     = categoryDto.Enabled,
                Id          = categoryDto.Id,
                Literal     = categoryDto.Literal
            };


            var children = _varietiesDtoList.Where(v => v.ParentId == categoryDto.Id);

            if (children != null)
            {
                model.Varieties.Clear();
                foreach (var dto in children)
                {
                    var v = new VarietyViewModel
                    {
                        Description = dto.Description,
                        Enabled     = dto.Enabled,
                        Id          = dto.Id,
                        Literal     = dto.Literal
                    };
                    v.Categories.Clear();
                    v.Categories.AddRange(CreateSelectList("Parent Category", _categoriesDtoList));

                    v.Parent = new CategoryViewModel
                    {
                        Description = categoryDto.Description,
                        Enabled     = categoryDto.Enabled,
                        Id          = categoryDto.Id,
                        Literal     = categoryDto.Literal
                    };
                    model.Varieties.Add(v);
                }
            }

            return(model);
        }
示例#4
0
        public VarietyViewModel CreateVarietyViewModel(ICode varietyDto, ICode parentDto)
        {
            if (varietyDto == null)
            {
                throw new ArgumentNullException(nameof(varietyDto));
            }

            var model = new VarietyViewModel
            {
                Description = varietyDto.Description,
                Enabled     = varietyDto.Enabled,
                Id          = varietyDto.Id,
                Literal     = varietyDto.Literal
            };

            model.Categories.AddRange(CreateSelectList("Parent Category", _categoriesDtoList));

            if (parentDto != null)
            {
                model.Parent = CreateCategoryViewModel(parentDto);
            }

            return(model);
        }