Пример #1
0
        public ActionResult Create([Bind(Include = "ID,Designation,TheDescription")] Mission mission)
        {
            if (ModelState.IsValid)
            {
                db.Missions.Add(mission);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(mission));
        }
Пример #2
0
        public ActionResult Create([Bind(Include = "ID,AstronautName,Birthday,CountryID")] Astronaut astronaut)
        {
            if (ModelState.IsValid)
            {
                db.Astronauts.Add(astronaut);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CountryID = new SelectList(db.Countries, "ID", "Nationality", astronaut.CountryID);
            return(View(astronaut));
        }
Пример #3
0
        public ActionResult Create([Bind(Include = "ID,Position,AstronautID,MissionID")] Crew crew)
        {
            if (ModelState.IsValid)
            {
                db.Crews.Add(crew);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.AstronautID = new SelectList(db.Astronauts, "ID", "AstronautName", crew.AstronautID);
            ViewBag.MissionID   = new SelectList(db.Missions, "ID", "Designation", crew.MissionID);
            return(View(crew));
        }
Пример #4
0
        public bool CreateAstronaut(string name, string surname, DateTime dateOfBirth, string superpower)
        {
            if (dateOfBirth > DateTime.Now)
            {
                return(false);
            }

            var astronaut = new Astronaut {
                Name = name, Surname = surname, DateOfBirth = dateOfBirth, Superpower = superpower
            };

            _context.Astronaut.Add(astronaut);

            try
            {
                _context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(false);
            }

            return(true);
        }