Ejemplo n.º 1
0
        public async Task UpdateBeer(string id, BeerBinding binding)
        {
            using (var context = GetMainContext())
            {
                var beer = await context.Beers.SingleOrDefaultAsync(x => x.ValueId == id);

                var entity = binding.ToEntity(context, beer);

                await context.SaveChangesAsync();
            }
        }
Ejemplo n.º 2
0
        public static Beer ToEntity(this BeerBinding binding, MainContext context, Beer beer = null)
        {
            var b = beer.DefaultIfNull();

            b.Abv     = binding.Abv;
            b.Name    = binding.Name;
            b.ValueId = beer?.ValueId ?? binding.Name.ToValueId();

            b.BeerBrandId = string.IsNullOrWhiteSpace(binding.BrandId) ? b.BeerBrandId : context.BeerBrands.GetId(binding.BrandId).Value;
            b.BeerStyleId = context.BeerStyles.GetId(binding.StyleId);

            return(b);
        }
Ejemplo n.º 3
0
        public async Task <string> CreateBeer(string brandValueId, BeerBinding binding)
        {
            using (var context = GetMainContext())
            {
                binding.BrandId = brandValueId;
                var entity = binding.ToEntity(context);
                await context.Beers.AddAsync(entity);

                await context.SaveChangesAsync();

                return(entity.ValueId);
            }
        }
Ejemplo n.º 4
0
 public async Task PutBeer(string beerId, [FromBody] BeerBinding binding) => await _beerHandler.UpdateBeer(beerId, binding);
Ejemplo n.º 5
0
 public async Task <IActionResult> PostBeer(string brandId, [FromBody] BeerBinding binding) => Ok(await _beerHandler.CreateBeer(brandId, binding));