Ejemplo n.º 1
0
        private async Task AddHopsAsSelectedItems(CreateStyleViewModel styleViewModel)
        {
            var hops = (await _homebrewApiService.GetAllHops())
                       .Select(h => new SelectListItem(h.Name, h.Id))
                       .ToList();

            styleViewModel.AddHopsAsSelectedItems(hops);
        }
Ejemplo n.º 2
0
        private async Task AddFermentablesAsSelectedItems(CreateStyleViewModel style)
        {
            var fermentables = (await _homebrewApiService.GetAllFermentables())
                               .Select(f => new SelectListItem(f.Name, f.Id))
                               .ToList();

            style.AddFermentablesAsSelectedItems(fermentables);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create()
        {
            var style = new CreateStyleViewModel();

            await AddFermentablesAsSelectedItems(style);
            await AddHopsAsSelectedItems(style);
            await AddYeastsAsSelectedItems(style);

            return(View(style));
        }
Ejemplo n.º 4
0
        private Style GetStyle(CreateStyleViewModel styleViewModel)
        {
            var style = _mapper.Map <Style>(styleViewModel);

            style.Thresholds.Add(_mapper.Map <StyleThreshold>(styleViewModel.AbvThreshold));
            style.Thresholds.Add(_mapper.Map <StyleThreshold>(styleViewModel.IbuThreshold));
            style.Thresholds.Add(_mapper.Map <StyleThreshold>(styleViewModel.ColorThreshold));

            style.CommonGrains.AddRange(styleViewModel.SelectedCommonGrains
                                        .Where(cg => cg.FermentableId != null)
                                        .Select(cg => _mapper.Map <CommonGrain>(cg)));
            style.CommonHops.AddRange(styleViewModel.SelectedCommonHops
                                      .Where(ch => ch.HopId != null)
                                      .Select(ch => _mapper.Map <CommonHop>(ch)));
            return(style);
        }
Ejemplo n.º 5
0
        public ActionResult Create(CreateStyleViewModel model)
        {
            try
            {
                if (false == ModelState.IsValid)
                {
                    return(View(model));
                }

                var style = _styleOrchestrator.CreateStyle(model.Name, model.Color, model.Glass);
                return(RedirectToAction("Details", "Style", new { id = style.Id }));
            }
            catch
            {
                return(View(model));
            }
        }
Ejemplo n.º 6
0
        public async Task <ActionResult> Create(CreateStyleViewModel styleViewModel)
        {
            if (ModelState.IsValid)
            {
                var style    = GetStyle(styleViewModel);
                var response = await _homebrewApiService.CreateStyle(style);

                if (response)
                {
                    return(RedirectToAction("Styles"));
                }
                return(View(styleViewModel));
            }
            else
            {
                await AddFermentablesAsSelectedItems(styleViewModel);
                await AddHopsAsSelectedItems(styleViewModel);
                await AddYeastsAsSelectedItems(styleViewModel);
            }
            return(View(styleViewModel));
        }
Ejemplo n.º 7
0
        // GET: Admin/Style/Create
        public ActionResult Create()
        {
            var viewModel = new CreateStyleViewModel();

            return(View(viewModel));
        }
Ejemplo n.º 8
0
        private async Task AddYeastsAsSelectedItems(CreateStyleViewModel styleViewModel)
        {
            var yeasts = await _homebrewApiService.GetAllYeasts();

            yeasts.ForEach(y => styleViewModel.Yeasts.Add(new SelectListItem(y.Name, y.Id)));
        }