public async Task DeleteAsync(int presentationID) { Presentation presentation = null; Stopwatch timespan = Stopwatch.StartNew(); SiccoAppConfiguration.SuspendExecutionStrategy = true; DbContextTransaction tran = db.Database.BeginTransaction(); try { presentation = await db.Presentations.FindAsync(presentationID); if (presentation.PresentationStatus != PresentationStatus.Pending) { throw new Exception("No se puede eliminar Presentaciones cuyo estado no es PENDIENTE"); } var requirement = await db.Requirements.FindAsync(presentation.RequirementID); //if (requirement.RequirementStatus != RequirementStatus.Pending) // throw new Exception("No se puede adjuntar Presentaciones a Requerimientos que no estan PENDIENTES"); //Al eliminar la Presentacion el Requerimiento queda en estado PENDING requirement.RequirementStatus = RequirementStatus.Pending; await documentFileService.DeleteDocumentFileAsync(presentation.DocumentFiles); db.Presentations.Remove(presentation); db.Entry(requirement).State = EntityState.Modified; await db.SaveChangesAsync(); tran.Commit(); timespan.Stop(); log.TraceApi("SQL Database", "PresentationRepository.DeleteAsync", timespan.Elapsed, "presentationID={0}", presentationID); } catch (Exception e) { tran.Rollback(); log.Error(e, "Error in PresentationRepository.DeleteAsync(presentationID={0})", presentationID); throw; } SiccoAppConfiguration.SuspendExecutionStrategy = false; }
public void DeleteByProductIDAsync(int productID) { //Eliminamos los archivos fisicos var productDocuments = productDocumentRepository.FindProductDocumentsByProductID(productID); if (productDocuments != null) { foreach (ProductDocument pd in productDocuments) { documentFileService.DeleteDocumentFileAsync(pd.ProductDocumentPDF); } } //Eliminamos la tabla que lo contiene productDocumentRepository.DeleteByProductIDAsync(productID); }