public async Task <IHttpActionResult> Delete(int id) { var flag = await memoryService.GetById(id); if (flag == null) { return(NotFound()); } try { if (!await memoryService.DeleteCheckOnEntity(id)) { await memoryService.Delete(id); } else { throw new Exception("Exist ForeingKeys"); } return(Ok()); } catch (Exception e) { return(InternalServerError(e)); } }