Exemple #1
0
        public static List <string> Handle(DeleteDocumentCommand command)
        {
            var document = GetDocumentByIdQuery.Get(new GetDocumentByIdRequest {
                Id = command.Id
            });
            var warnings = new List <string>();

            foreach (var scan in document.Scans)
            {
                var fi = new FileInfo(scan.Filename);
                try
                {
                    if (fi.Exists)
                    {
                        fi.Delete();
                    }
                }
                catch (Exception e)
                {
                    warnings.Add($"{e.Message}");
                }
            }

            DeleteDocumentQuery.Delete(command);

            return(warnings);
        }
        public static void Delete(DeleteDocumentCommand command)
        {
            using (var connection = AppConfig.Connections.ScanDbConnection)
            {
                const string deleteScansQuery = "DELETE FROM Scans " +
                                                "WHERE DocumentId = @Id";

                connection.Execute(deleteScansQuery, command);

                const string deleteCustomFieldsQuery = "DELETE FROM DocumentCustomFields " +
                                                       "WHERE DocumentId = @Id";

                connection.Execute(deleteCustomFieldsQuery, command);

                const string deleteDocumentQuery = "DELETE FROM documents " +
                                                   "WHERE Id = @Id";

                connection.Execute(deleteDocumentQuery, command);
            }
        }