Ejemplo n.º 1
0
        public async Task <IActionResult> Create(FlightsCreateViewModel model)
        {
            if ((model.TimeOfLanding - model.TimeOfDepartment).TotalMinutes < 30)
            {
                ModelState.AddModelError(nameof(model.TimeOfLanding), "The shortest flight is 30 minutes");
            }

            if (!ModelState.IsValid)
            {
                return(View());
            }

            Flight flight = new Flight()
            {
                Id                     = Guid.NewGuid().ToString(),
                StartLocation          = model.StartLocation,
                FinalLocation          = model.FinalLocation,
                TimeOfDepartment       = model.TimeOfDepartment,
                TimeOfLanding          = model.TimeOfLanding,
                PlaneType              = model.PlaneType,
                PlaneNumber            = model.PlaneNumber,
                PilotName              = model.PilotName,
                EconomyClassCapacity   = model.EconomyClassCapacity,
                BuissnessClassCapacity = model.BuissnessClassCapacity
            };

            await this.context.AddAsync(flight);

            await this.context.SaveChangesAsync();

            return(Redirect("~/Home"));
        }
        public async Task <IActionResult> Create(FlightsCreateViewModel createModel)
        {
            if (ModelState.IsValid)
            {
                Flight flight = new Flight
                {
                    LocationFrom            = createModel.LocationFrom,
                    LocationTo              = createModel.LocationTo,
                    Going                   = createModel.Going,
                    Return                  = createModel.Return,
                    TypeOfPlane             = createModel.TypeOfPlane,
                    NameOfAviator           = createModel.NameOfAviator,
                    CapacityOfEconomyClass  = createModel.CapacityOfEconomyClass,
                    CapacityOfBusinessClass = createModel.CapacityOfBusinessClass
                };
                _context.Add(flight);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(createModel));
        }
        //GET: Flight/Create

        public IActionResult Create()
        {
            FlightsCreateViewModel model = new FlightsCreateViewModel();

            return(View(model));
        }