public async Task <IActionResult> PutEntity(int id, TemplateEntity entity) { if (id != entity.Id) { return(BadRequest()); } try { _context.Update(entity); _context.Entry(entity).State = EntityState.Modified; await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException e) { System.Diagnostics.Debug.WriteLine(e.Message); if (!EntityExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Grade")] TemplateEntity entity) { if (id != entity.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(entity); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException e) { System.Diagnostics.Debug.WriteLine(e.Message); if (!EntityExists(entity.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["Grade"] = new SelectList(_context.TemplateClasses, "Grade", "Grade", entity.Grade); return(View(entity)); }
public async Task <ActionResult <TemplateEntity> > Put(int id, TemplateEntity entity) { // Add your code below, this is an example for basic implementation if (!ModelState.IsValid) { return(BadRequest()); } try { _context.Update(entity); _context.Entry(entity).State = EntityState.Modified; await _context.SaveChangesAsync(); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); return(StatusCode(401)); } return(StatusCode(201)); }