public async Task <IActionResult> Edit(string id, [Bind("HookId,Title,Description,Id,Prefetch,CodeType,Code")] ServiceViewModel serviceViewModel) { if (id != serviceViewModel.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(serviceViewModel.ToEntity()); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CDSServiceExists(serviceViewModel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewBag.HookId = new SelectList(_context.Hooks, "Id", "Id", serviceViewModel.HookId); ViewBag.isEdit = true; return(View("CreateEdit", serviceViewModel)); }
public async Task <IActionResult> Create([Bind("HookId,Title,Description,Id,Prefetch,CodeType,Code")] ServiceViewModel serviceViewModel) { if (ModelState.IsValid) { _context.Add(serviceViewModel.ToEntity()); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewBag.HookId = new SelectList(_context.Hooks, "Id", "Id", serviceViewModel.HookId); return(View("CreateEdit", serviceViewModel)); }
public async Task <IActionResult> Create(ServiceViewModel model) { if (ModelState.IsValid) { var service = model.ToEntity(); _context.Services.Add(service); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(model)); }