Beispiel #1
0
        public async Task <IActionResult> Create(AddInstrumentViewModel vm)
        {
            int quantity = vm.Quantity;

            if (ModelState.IsValid)
            {
                for (int i = 0; i < quantity; i++)
                {
                    InstrumentInventory instrumentInventory = new InstrumentInventory();
                    instrumentInventory.InstrumentId = vm.InstrumentId;
                    instrumentInventory.Manufacturer = vm.Manufacturer;
                    instrumentInventory.PurchaseDate = DateTime.Now;
                    instrumentInventory.Cost         = vm.Cost;
                    _context.Add(instrumentInventory);
                }

                await _context.SaveChangesAsync();

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

            foreach (var error in ViewData.ModelState.Values.SelectMany(modelState => modelState.Errors))
            {
                var test = error;
            }



            ViewData["InstrumentId"] = new SelectList(_context.Instrument, "InstrumentId", "Instrument1", vm.InstrumentId);
            return(View(vm));
        }
Beispiel #2
0
 public IActionResult AddInstrument([FromForm] AddInstrumentViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest());
     }
     instrumentServices.AddInstrument(model.Name, model.Type, model.OrchestraId);
     return(Redirect(Url.Action("Index", "Instruments")));
 }