public async Task <ActionResult> Create([FromBody] SalesOrder salesOrder) { if (ModelState.IsValid) { if (salesOrder == null) { return(BadRequest()); } var repository = new SalesOrdersRepository(_context); try { await repository.Insert(salesOrder); repository.Save(); return(NoContent()); } catch (Exception e) { return(BadRequest(new { message = e.Message.Replace('{', '(').Replace('}', ')') })); } } return(BadRequest(new { message = "ModelState is not valid" })); }
public async Task <ActionResult> Delete(int id) { var repository = new SalesOrdersRepository(_context); SalesOrder salesOrder = await repository.GetById(id); if (salesOrder == null) { return(NotFound()); } try { repository.Delete(salesOrder); repository.Save(); return(NoContent()); } catch (Exception e) { return(BadRequest(new { message = e.Message.Replace('{', '(').Replace('}', ')') })); } }