public TestSubTable Add(TestSubTable testSubTable) { // Pretend description is required if (string.IsNullOrEmpty(testSubTable.Testsubdescription)) { throw new InvalidInputException("Required field missing."); } _context.Add(testSubTable); _context.SaveChanges(); return(testSubTable); }
public void Update(TestSubTable testSubTable) { var existingSubTable = _context.TestSubTable.Find(testSubTable.Testsubid); if (existingSubTable == null) { throw new ItemNotFoundException($"TestSubTable {testSubTable.Testsubid} not found."); } if (string.IsNullOrEmpty(testSubTable.Testsubdescription)) { throw new InvalidInputException("Required field missing."); } existingSubTable.Testsubdescription = testSubTable.Testsubdescription; existingSubTable.Testsubdate = testSubTable.Testsubdate; _context.TestSubTable.Update(existingSubTable); _context.SaveChanges(); }
public ActionResult Update([FromBody] TestSubTable testSubTable) { try { _testSubService.Update(testSubTable); return(NoContent()); } catch (Exception ex) { if (ex is ItemNotFoundException) { return(NotFound()); } else if (ex is InvalidInputException) { return(BadRequest()); } return(StatusCode(500)); } }
public ActionResult AddSubTable([FromBody] TestSubTable testSubTable) { try { _testSubService.Add(testSubTable); return(CreatedAtAction("GetSubTable", new { id = testSubTable.Testid }, testSubTable)); } catch (Exception ex) { if (ex is ItemNotFoundException) { return(NotFound()); } else if (ex is InvalidInputException) { return(BadRequest()); } return(StatusCode(500)); } }