/// <summary> /// Generates the export files. /// </summary> /// <param name="relatedTable">The related table.</param> /// <param name="relatedId">The related identifier.</param> /// <param name="userId">The user identifier.</param> public void GenerateExportFiles(string relatedTable, int relatedId, int userId) { int deletedExpotFileStatusCodeId = Utils.GetCodeByValue("ExportFileStatus", "DELETED").CodeId; // check if a record already exisit Data.ExportFile exportFile = DataContext.ExportFiles.Where(ef => ef.RelatedId == relatedId && ef.RelatedTable == relatedTable && ef.IsActive && ef.ExportFileStatusCodeId != deletedExpotFileStatusCodeId).FirstOrDefault(); if (exportFile == null) { exportFile = new ExportFile { RelatedTable = relatedTable, RelatedId = relatedId, ExportFileStatusCodeId = Utils.GetCodeByValue("ExportFileStatus", "QUEUED").CodeId, CreatedByUserId = userId, LastUpdatedByUserId = userId, CreatedDate = Utils.Now, LastUpdatedDate = Utils.Now, IsActive = true }; DataContext.ExportFiles.AddObject(exportFile); DataContext.SaveChanges(); } }
/// <summary> /// Deletes the exported file. /// </summary> /// <param name="relatedTable">The related table.</param> /// <param name="relatedId">The related identifier.</param> /// <param name="userId">The user identifier.</param> public void DeleteExportedFile(string relatedTable, int relatedId, int userId) { int deletedExpotFileStatusCodeId = Utils.GetCodeByValue("ExportFileStatus", "DELETED").CodeId; // check if a record already exisit Data.ExportFile exportFile = DataContext.ExportFiles.Where(ef => ef.RelatedId == relatedId && ef.RelatedTable == relatedTable && ef.IsActive && ef.ExportFileStatusCodeId != deletedExpotFileStatusCodeId).FirstOrDefault(); if (exportFile != null) { //IsActive is not set to false. It get set after the agent physically delete the file exportFile.ExportFileStatusCodeId = Utils.GetCodeByValue("ExportFileStatus", "DELETED").CodeId; exportFile.LastUpdatedByUserId = userId; exportFile.LastUpdatedDate = Utils.Now; DataContext.SaveChanges(); } }