Esempio n. 1
0
        public async Task <IActionResult> Create(EngineViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _context.Add(new Models.Engine()
                    {
                        Name     = model.Name,
                        SeaLevel = new Models.Performance()
                        {
                            Isp    = model.SeaLevel.Isp,
                            Thrust = model.SeaLevel.Thrust
                        },
                        Vacuum = new Models.Performance()
                        {
                            Isp    = model.Vacuum.Isp,
                            Thrust = model.Vacuum.Thrust
                        }
                    });

                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
                catch (DbUpdateException)
                {
                    ModelState.AddModelError("", "Unable to create new engine");
                }
            }

            return(View(model));
        }