public async Task <IActionResult> Create(int agencyId, [Bind("Id,Title,StartDate,EndDate,Target,StateId")] SpacePrograms spacePrograms, IFormCollection collection)
        {
            if (await findProgramWithTheSameName(spacePrograms) != null)
            {
                ModelState.AddModelError(String.Empty, "Program with this name already exists");
            }

            if (ModelState.IsValid)
            {
                AgenciesPrograms newPair = new AgenciesPrograms();

                var agency = _context.SpaceAgencies.Where(a => a.Id == agencyId).FirstOrDefault();
                newPair.SpaceAgency    = agency;
                newPair.SpaceProgram   = spacePrograms;
                newPair.SpaceAgencyId  = agencyId;
                newPair.SpaceProgramId = spacePrograms.Id;
                spacePrograms.AgenciesPrograms.Add(newPair);
                agency.AgenciesPrograms.Add(newPair);
                _context.Add(spacePrograms);
                _context.Add(newPair);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(spacePrograms));
        }
        public async Task <IActionResult> Create(int crewId, [Bind("Id,Name,Surname,BirthDate,Duty,CrewId,CountryId")] Astronauts astronaut)
        {
            if (ModelState.IsValid)
            {
                CrewsAstronauts newPair = new CrewsAstronauts();
                newPair.CrewId      = crewId;
                newPair.AstronautId = astronaut.Id;
                newPair.Crew        = _context.Crews.Where(c => c.Id == crewId).FirstOrDefault();
                newPair.Astronaut   = astronaut;
                _context.Add(astronaut);
                _context.Add(newPair);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CountryId"] = new SelectList(_context.Countires, "Id", "CountryName", astronaut.CountryId);
            return(View(astronaut));
        }
        public async Task <IActionResult> Create([Bind("Id,StateName")] States states)
        {
            if (ModelState.IsValid)
            {
                _context.Add(states);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(states));
        }
        public async Task <IActionResult> Create([Bind("Id,StartDate,EndDate,Title,IsRobotic,ProgramId")] Missions missions)
        {
            if (ModelState.IsValid)
            {
                _context.Add(missions);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Program"] = new SelectList(_context.SpacePrograms, "Id", "Title", missions.ProgramId);
            return(View(missions));
        }
        public async Task <IActionResult> Create([Bind("Id,SpaceAgencyId,SpaceProgramId")] AgenciesPrograms agenciesPrograms)
        {
            if (ModelState.IsValid)
            {
                _context.Add(agenciesPrograms);
                await _context.SaveChangesAsync();

                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));
        }
示例#6
0
        public async Task <IActionResult> Create([Bind("Id,StateId,ProgramId")] ProgramsStates programsStates)
        {
            if (ModelState.IsValid)
            {
                _context.Add(programsStates);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProgramId"] = new SelectList(_context.SpacePrograms, "Id", "Target", programsStates.ProgramId);
            ViewData["StateId"]   = new SelectList(_context.States, "Id", "StateName", programsStates.StateId);
            return(View(programsStates));
        }
示例#7
0
        public async Task <IActionResult> Create([Bind("Id,CrewId,AstronautId")] CrewsAstronauts crewsAstronauts)
        {
            if (ModelState.IsValid)
            {
                _context.Add(crewsAstronauts);
                await _context.SaveChangesAsync();

                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));
        }
示例#8
0
        public async Task <IActionResult> Create([Bind("Id,CountryName,Gdp,Population")] Countires countires)
        {
            if (await findCountriesWithTheSameName(countires) != null)
            {
                ModelState.AddModelError(String.Empty, "Country with this name already exists");
            }
            if (ModelState.IsValid)
            {
                _context.Add(countires);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(countires));
        }
        public async Task<IActionResult> Create([Bind("Id,Name,DateOfEstablishment,Budget,HeadquarterCountryId")] SpaceAgencies 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");
            if (ModelState.IsValid)
            {
                _context.Add(spaceAgencies);
                 await _context.SaveChangesAsync();
                return RedirectToAction(nameof(Index));   
            }
            ViewData["HeadquarterCountry"] = new SelectList(_context.Countires, "Id", "CountryName", spaceAgencies.HeadquarterCountryId);
            return View(spaceAgencies);

        }
示例#10
0
        public async Task <IActionResult> Create([Bind("Id,Name,Surname,BirthDate,SpaceAgencyId")] Administrators administrators)
        {
            if (await findAdministratorInTheSameAgency(administrators) != null)
            {
                ModelState.AddModelError(String.Empty, "There couldn't be more than 1 admin in the same agency");
            }
            if (ModelState.IsValid)
            {
                _context.Add(administrators);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Agency"] = new SelectList(_context.SpaceAgencies, "Id", "Name", administrators.SpaceAgencyId);
            return(View(administrators));
        }
        public async Task <IActionResult> Create([Bind("Id,NumberOfMembers,MissionId")] Crews crews)
        {
            if (await _context.Crews.FirstOrDefaultAsync(c => c.MissionId == crews.MissionId) != null)
            {
                ModelState.AddModelError(String.Empty, "This mission already has a crew");
            }
            if (ModelState.IsValid)
            {
                _context.Add(crews);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Mission"] = new SelectList(_context.Missions, "Id", "Title", crews.MissionId);
            return(View(crews));
        }