public async Task <IActionResult> Edit(int id, [Bind("Id,CarriageId,LocomotiveId,FreeSeats")] CarriageHasLocomotive carriageHasLocomotive)
        {
            if (id != carriageHasLocomotive.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(carriageHasLocomotive);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CarriageHasLocomotiveExists(carriageHasLocomotive.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CarriageId"]   = new SelectList(_context.Carriage, "Id", "Id", carriageHasLocomotive.CarriageId);
            ViewData["LocomotiveId"] = new SelectList(_context.Locomotive, "Id", "Id", carriageHasLocomotive.LocomotiveId);
            return(View(carriageHasLocomotive));
        }
 public CarriageView(CarriageHasLocomotive element, int destination)
 {
     carriageNumber = element.Carriage.Number;
     carriageType   = element.Carriage.CarriageType.Name;
     price          = element.Carriage.CarriageType.Pricefactor * destination;
     freeSeats      = element.FreeSeats;
     id             = element.CarriageId;
 }
        public async Task <IActionResult> Create([Bind("Id,CarriageId,LocomotiveId,FreeSeats")] CarriageHasLocomotive carriageHasLocomotive)
        {
            if (ModelState.IsValid)
            {
                _context.Add(carriageHasLocomotive);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CarriageId"]   = new SelectList(_context.Carriage, "Id", "Id", carriageHasLocomotive.CarriageId);
            ViewData["LocomotiveId"] = new SelectList(_context.Locomotive, "Id", "Id", carriageHasLocomotive.LocomotiveId);
            return(View(carriageHasLocomotive));
        }