public async Task <ActionResult> Put(int id, product_directory directory) { if (ModelState.IsValid) { directory.product_directory_id = id; string problem = ConstraintsTest(directory).Result; if (problem != null) { var result = dbContext.fdc_product_directories.Update(directory); if (result != null && result.State == EntityState.Modified) { await dbContext.SaveChangesAsync(); var response = await dbContext.GetDirectory(result.Entity.product_directory_id); return(Ok(response)); } return(NotFound()); } return(NotFound(problem)); } return(BadRequest()); }
/// <summary> /// Проверка на существования связанных сущностей в БД /// </summary> private async Task <string> ConstraintsTest(product_directory directory) { if (directory.parent_id == 0) { directory.parent_id = null; directory.parent = null; } else { directory.parent = await dbContext.GetDirectory(directory.parent_id); if (directory.parent == null) { return("Не найден родительский раздел"); } } return(""); }