Ejemplo n.º 1
0
 public async Task <IActionResult> Edit(int id, [Bind("Id,CountryName,Gdp,Population")] Countires countires)
 {
     if (id != countires.Id)
     {
         return(NotFound());
     }
     if (await findCountriesWithTheSameName(countires) != null)
     {
         ModelState.AddModelError(String.Empty, "Country with this name already exists");
     }
     if (ModelState.IsValid)
     {
         try
         {
             _context.Update(countires);
             await _context.SaveChangesAsync();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!CountiresExists(countires.Id))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         return(RedirectToAction(nameof(Index)));
     }
     return(View(countires));
 }
        public async Task <IActionResult> Edit(int id, [Bind("Id,NumberOfMembers,MissionId")] Crews crews)
        {
            if (id != crews.Id)
            {
                return(NotFound());
            }

            if (await _context.Crews.FirstOrDefaultAsync(c => c.MissionId == crews.MissionId) != null)
            {
                ModelState.AddModelError(String.Empty, "This mission ");
            }
            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(crews);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CrewsExists(crews.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Mission"] = new SelectList(_context.Missions, "Id", "Title", crews.MissionId);
            return(View(crews));
        }
Ejemplo n.º 3
0
 public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Surname,BirthDate,SpaceAgencyId")] Administrators administrators)
 {
     if (id != administrators.Id)
     {
         return(NotFound());
     }
     if (await findAdministratorInTheSameAgency(administrators) != null)
     {
         ModelState.AddModelError(String.Empty, "There couldn't be more than 1 admin in the same agency");
     }
     if (ModelState.IsValid)
     {
         try
         {
             _context.Update(administrators);
             await _context.SaveChangesAsync();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!AdministratorsExists(administrators.Id))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         return(RedirectToAction(nameof(Index)));
     }
     ViewData["Agency"] = new SelectList(_context.SpaceAgencies, "Id", "Name", administrators.SpaceAgencyId);
     return(View(administrators));
 }
        public async Task <IActionResult> Edit(int id, [Bind("Id,StartDate,EndDate,Title,IsRobotic,ProgramId")] Missions missions)
        {
            if (id != missions.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(missions);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MissionsExists(missions.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Program"] = new SelectList(_context.SpacePrograms, "Id", "Title", missions.ProgramId);
            return(View(missions));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,SpaceAgencyId,SpaceProgramId")] AgenciesPrograms agenciesPrograms)
        {
            if (id != agenciesPrograms.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(agenciesPrograms);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AgenciesProgramsExists(agenciesPrograms.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["SpaceAgencyId"]  = new SelectList(_context.SpaceAgencies, "Id", "Name", agenciesPrograms.SpaceAgencyId);
            ViewData["SpaceProgramId"] = new SelectList(_context.SpacePrograms, "Id", "Target", agenciesPrograms.SpaceProgramId);
            return(View(agenciesPrograms));
        }
        public async Task<IActionResult> Edit(int id, [Bind("Id,Name,DateOfEstablishment,Budget,HeadquarterCountryId")] SpaceAgencies spaceAgencies)
        {
            if (id != spaceAgencies.Id)
            {
                return NotFound();
            }
             if (ModelState.IsValid)
            {
                try
                {
                    
                    _context.Update(spaceAgencies);
                    if (await findAgencyInTheSameCountry(spaceAgencies) != null) ModelState.AddModelError(String.Empty, "This country already has an agency");
                    if (await findAgencyWithTheSameName(spaceAgencies) != null) ModelState.AddModelError(String.Empty, "Agency with this name already exists");
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {


                    if (!SpaceAgenciesExists(spaceAgencies.Id))
                    {
                        return NotFound();
                    }
                    else
                    {
                        throw;
                    }
                }
                return RedirectToAction(nameof(Index));
            }
            ViewData["HeadquarterCountry"] = new SelectList(_context.Countires, "Id", "CountryName", spaceAgencies.HeadquarterCountryId);
            return View(spaceAgencies);
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,CrewId,AstronautId")] CrewsAstronauts crewsAstronauts)
        {
            if (id != crewsAstronauts.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(crewsAstronauts);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CrewsAstronautsExists(crewsAstronauts.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AstronautId"] = new SelectList(_context.Astronauts, "Id", "Duty", crewsAstronauts.AstronautId);
            ViewData["CrewId"]      = new SelectList(_context.Crews, "Id", "Id", crewsAstronauts.CrewId);
            return(View(crewsAstronauts));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,StateName")] States states)
        {
            if (id != states.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(states);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StatesExists(states.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(states));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Surname,BirthDate,Duty,CrewId,CountryId")] Astronauts astronauts)
        {
            if (id != astronauts.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    //CrewsAstronauts pair = _context.CrewsAstronauts.Where(ca => ca.AstronautId == astronauts.Id).FirstOrDefault();
                    //pair.CrewId = astronauts.CrewId;
                    //pair.Crew = _context.Crews.Where(c => c.Id == astronauts.CrewId).FirstOrDefault();
                    _context.Update(astronauts);
                    //_context.Update(pair);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AstronautsExists(astronauts.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CountryId"] = new SelectList(_context.Countires, "Id", "CountryName", astronauts.CountryId);
            return(View(astronauts));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,StartDate,EndDate,Target,AgencyId")] SpacePrograms spacePrograms)
        {
            if (id != spacePrograms.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(spacePrograms);
                    if (await findProgramWithTheSameName(spacePrograms) != null)
                    {
                        ModelState.AddModelError(String.Empty, "Program with this name already exists");
                    }
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SpaceProgramsExists(spacePrograms.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }


            return(View(spacePrograms));
        }