public async Task <IActionResult> Edit(int id, [Bind("ModelId,MakeId,ModelName")] Core.StoreModels.Models models) { if (id != models.ModelId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(models); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ModelsExists(models.ModelId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["MakeId"] = new SelectList(_context.Makes, "MakeId", "MakeName", models.MakeId); return(View(models)); }
public async Task <IActionResult> Create([Bind("ModelId,MakeId,ModelName")] Core.StoreModels.Models models) { if (ModelState.IsValid) { _context.Add(models); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["MakeId"] = new SelectList(_context.Makes, "MakeId", "MakeName", models.MakeId); return(View(models)); }
public async Task <ActionResult <string> > Save([FromBody] Core.StoreModels.Models data) { try { var itm = new Core.StoreModels.Models() { MakeId = data.MakeId, ModelName = data.ModelName, ModelId = 0 }; var existBefore = await _context.Models.Where(m => m.ModelName == data.ModelName).ToListAsync(); if (existBefore.Count() == 0) // not exist before then add. { _context.Add(itm); await _context.SaveChangesAsync(); } return(Ok(itm.ModelId)); } catch { return(Ok(data.ModelName)); } }