Example #1
0
        public async Task <ActionResult <MashStep> > PostMashStep(MashStep mashStep)
        {
            _context.MashStep.Add(mashStep);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetMashStep", new { id = mashStep.MashStepId }, mashStep));
        }
        // private readonly IFermentableElasticsearch _fermentableElasticsearch = new FermentableElasticsearch();
        //private readonly IFermentableRepository _fermentableRepository = new FermentableDapperRepository();

        protected override IList <FermentableStepDto> ResolveCore(MashStep step)
        {
            var fermentableStepDtoList = new List <FermentableStepDto>();

            // foreach (var item in step.Fermentables)
            // {
            //     var fermentable = _fermentableElasticsearch.GetSingle(item.FermentableId);
            //     if (fermentable == null)
            //     {
            //         fermentable = Mapper.Map<Fermentable, FermentableDto>(_fermentableRepository.GetSingle(item.FermentableId));
            //     }
            //     var fermentableStepDto = new FermentableStepDto
            //     {
            //         FermentableId = item.FermentableId,
            //         Amount = item.Amount,
            //         Supplier = fermentable.Supplier,
            //         SubType = fermentable.Type,
            //         Name = fermentable.Name,
            //         PPG = fermentable.PPG,
            //     };
            //     if(item.Lovibond == 0)
            //     {
            //         fermentableStepDto.Lovibond = item.Lovibond;
            //     }
            //     else
            //     {
            //         fermentableStepDto.Lovibond = fermentable.Lovibond;
            //     }
            //     fermentableStepDtoList.Add(fermentableStepDto);
            // }

            return(fermentableStepDtoList);
        }
Example #3
0
        public async Task <IActionResult> PutMashStep(int id, MashStep mashStep)
        {
            if (id != mashStep.MashStepId)
            {
                return(BadRequest());
            }

            _context.Entry(mashStep).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MashStepExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        protected override IList <HopStepDto> ResolveCore(MashStep step)
        {
            var hopStepDtoList = new List <HopStepDto>();

            foreach (var item in step.Hops)
            {
                var hopStepDto = new HopStepDto()
                {
                    HopId      = item.HopId,
                    StepNumber = item.StepNumber,
                    Amount     = item.Amount,
                    AAValue    = item.AAValue,
                    RecipeId   = item.RecipeId,
                };
                var hop = _hopElasticsearch.GetSingle(item.HopId) ?? Mapper.Map <Hop, HopDto>(_hopRepository.GetSingle(item.HopId));
                hopStepDto.Name   = hop.Name;
                hopStepDto.Origin = hop.Origin;
                //hopStepDto.Flavours = hop.Flavours;
                //hopStepDto.FlavourDescription = hop.FlavourDescription;
                //TODO: Add elasticsearch on hop form.
                hopStepDto.HopForm = Mapper.Map <HopForm, DTO>(_hopRepository.GetForm(item.HopFormId));
                hopStepDtoList.Add(hopStepDto);
            }
            return(hopStepDtoList);
        }
        protected override IList <FermentableStepDto> ResolveCore(MashStep step)
        {
            var fermentableStepDtoList = new List <FermentableStepDto>();

            foreach (var item in step.Fermentables)
            {
                var fermentable = _fermentableElasticsearch.GetSingle(item.FermentableId);
                if (fermentable == null)
                {
                    fermentable = Mapper.Map <Fermentable, FermentableDto>(_fermentableRepository.GetSingle(item.FermentableId));
                }
                var fermentableStepDto = new FermentableStepDto
                {
                    FermentableId = item.FermentableId,
                    StepNumber    = item.StepNumber,
                    Amount        = item.Amount,
                    Supplier      = fermentable.Supplier,
                    Type          = fermentable.Type,
                    Name          = fermentable.Name,
                    PPG           = fermentable.PPG,
                    RecipeId      = item.RecipeId
                };
                if (item.Lovibond == 0)
                {
                    fermentableStepDto.Lovibond = item.Lovibond;
                }
                else
                {
                    fermentableStepDto.Lovibond = fermentable.Lovibond;
                }
                fermentableStepDtoList.Add(fermentableStepDto);
            }

            return(fermentableStepDtoList);
        }
        protected override IList <IIngredientStepDto> ResolveCore(MashStep source)
        {
            var ingredients = new List <IIngredientStepDto>();

            // var hops = Mapper.Map<ICollection<MashStepHop>, IList<HopStepDto>>(source.Hops);
            // ingredients.AddRange(hops);
            // var fermentables = Mapper.Map<ICollection<MashStepFermentable>, IList<FermentableStepDto>>(source.Fermentables);
            // ingredients.AddRange(fermentables);
            // var others = Mapper.Map<ICollection<MashStepOther>, IList<OtherStepDto>>(source.Others);
            // ingredients.AddRange(others);
            return(ingredients);
        }
        // private readonly IOtherElasticsearch _otherElasticsearch = new OtherElasticsearch();
        // private readonly IOtherRepository _otherRepository = new OtherDapperRepository();

        protected override IList <OtherStepDto> ResolveCore(MashStep step)
        {
            var otherStepDtoList = new List <OtherStepDto>();

            // foreach (var item in step.Others)
            // {
            //     var otherStepDto = new OtherStepDto()
            //     {
            //         OtherId = item.OtherId,
            //         Amount = item.Amount,
            //     };
            //     var other = _otherElasticsearch.GetSingle(item.OtherId);
            //     if (other == null)
            //     {
            //         other = Mapper.Map<Other, OtherDto>(_otherRepository.GetSingle(item.OtherId));
            //     }
            //     otherStepDto.Name = other.Name;
            //     otherStepDto.SubType = other.Type;
            //     otherStepDtoList.Add(otherStepDto);
            // }
            return(otherStepDtoList);
        }
Example #8
0
        protected override IList <OtherStepDto> ResolveCore(MashStep step)
        {
            var otherStepDtoList = new List <OtherStepDto>();

            foreach (var item in step.Others)
            {
                var otherStepDto = new OtherStepDto()
                {
                    OtherId  = item.OtherId,
                    Amount   = item.Amount,
                    RecipeId = item.RecipeId,
                    Number   = item.StepNumber,
                };
                var other = _otherElasticsearch.GetSingle(item.OtherId);
                if (other == null)
                {
                    other = Mapper.Map <Other, OtherDto>(_otherRepository.GetSingle(item.OtherId));
                }
                otherStepDto.Name = other.Name;
                otherStepDto.Type = other.Type;
                otherStepDtoList.Add(otherStepDto);
            }
            return(otherStepDtoList);
        }