public async Task <IActionResult> Edit(int id, [Bind("Id,Nazwa,Typ,ZawartoscAlk,Ibu,Ekstrakt,BrowarId")] Piwo piwo)
        {
            if (id != piwo.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(piwo);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PiwoExists(piwo.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BrowarId"] = new SelectList(_context.Browary, "Id", "Nazwa", piwo.BrowarId);
            return(View(piwo));
        }
        public async Task <IHttpActionResult> PutPiwo(int id, Piwo piwo)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != piwo.Id)
            {
                return(BadRequest());
            }

            db.Entry(piwo).State = EntityState.Modified;

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IActionResult> Create([Bind("Id,Nazwa,Typ,ZawartoscAlk,Ibu,Ekstrakt,BrowarId")] Piwo piwo)
        {
            if (ModelState.IsValid)
            {
                _context.Add(piwo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BrowarId"] = new SelectList(_context.Browary, "Id", "Nazwa", piwo.BrowarId);
            return(View(piwo));
        }
        public async Task <IHttpActionResult> DeletePiwo(int id)
        {
            Piwo piwo = await db.Piwoes.FindAsync(id);

            if (piwo == null)
            {
                return(NotFound());
            }

            db.Piwoes.Remove(piwo);
            await db.SaveChangesAsync();

            return(Ok(piwo));
        }
        public async Task <IHttpActionResult> PostPiwo(Piwo piwo)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Piwoes.Add(piwo);
            await db.SaveChangesAsync();

            // New code:
            // Load author name
            db.Entry(piwo).Reference(x => x.Browarnia).Load();

            var dto = new PiwoDTO()
            {
                Id        = piwo.Id,
                Name      = piwo.Name,
                Browarnia = piwo.Browarnia.Name
            };

            return(CreatedAtRoute("DefaultApi", new { id = piwo.Id }, dto));
        }