Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] Fleet fleet)
        {
            if (id != fleet.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(fleet);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FleetExists(fleet.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(fleet));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,MaxWeight,FleetId")] Vessel vessel)
        {
            if (id != vessel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(vessel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!VesselExists(vessel.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["FleetId"] = new SelectList(_context.Fleets, "Id", "Id", vessel.FleetId);
            return(View(vessel));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Weight,VesselId")] Container container)
        {
            if (id != container.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                //Restrict weight
                var vessel = _context.Vessels.Where(x => x.Id == container.Id).FirstOrDefault();
                if (vessel == null || vessel.Containers.Sum(x => x.Weight) + container.Weight > vessel.MaxWeight)
                {
                    return(NotFound());
                }

                try
                {
                    _context.Update(container);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ContainerExists(container.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["VesselId"] = new SelectList(_context.Vessels, "Id", "Id", container.VesselId);
            return(View(container));
        }