public static void UpdateCourtFile(CRMHelper crmHelper, CommonHelper helper, Entity courtFile, string courtFileDoctitle)
{
try
{
EntityCollection workingDocumentEntityCollection = null;
if (courtFile.Attributes.ContainsKey(Constants.CourtFileEntity.Attributes.claim))
{
DateTime dateOfService;
DateTime dateOfApplication;
string timeofService;
List workingDocumentList = new List();
WorkingDocumentCollection workingDocumentCollection = GetWorkingDocumentColl(crmHelper, courtFile.GetAttributeValue(Constants.CourtFileEntity.Attributes.claim).Id, courtFile, true);
if (!courtFile.GetAttributeValue<bool>(Constants.CourtFileEntity.Attributes.IsFromClaim))
{
if (courtFile.GetAttributeValue<EntityReference>(Constants.CourtFileEntity.Attributes.application) != null)
{
workingDocumentCollection.Application = courtFile.GetAttributeValue<EntityReference>(Constants.CourtFileEntity.Attributes.application).Id.ToString();
}
}
if (courtFile.Attributes.Contains(Constants.CourtFileEntity.Attributes.Signature))
{
workingDocumentCollection.Signature = courtFile.GetAttributeValue<string>(Constants.CourtFileEntity.Attributes.Signature);
}
workingDocumentCollection.ClaimType = courtFileDoctitle;//+ DateTime.Now.ToString("yyyyMMddhhmmssfff");
workingDocumentCollection.CourtFileTitle = courtFileDoctitle;
if (courtFile.Attributes.ContainsKey(Constants.CourtFileEntity.Attributes.DateFiled)
&& courtFile.Attributes[Constants.CourtFileEntity.Attributes.DateFiled] != null
&& ((DateTime)courtFile.Attributes[Constants.CourtFileEntity.Attributes.DateFiled]) != DateTime.MinValue)
{
dateOfApplication = (DateTime)courtFile.Attributes[Constants.CourtFileEntity.Attributes.DateFiled];
workingDocumentCollection.ApplicationCreationDate = string.Format(
“{0}/{1}/{2}-{3}”,
dateOfApplication.Day,
dateOfApplication.Month,
dateOfApplication.Year,
DateTime.Now.ToLongTimeString());
}
else
{
dateOfApplication = DateTime.Now;
}
////if (courtFile.Attributes.ContainsKey(Constants.CourtFileEntity.Attributes.ListingDate)
////&& courtFile.Attributes[Constants.CourtFileEntity.Attributes.ListingDate] != null
////&& ((DateTime)courtFile.Attributes[Constants.CourtFileEntity.Attributes.ListingDate]) != DateTime.MinValue)
////{
//// dateOfService = (DateTime)courtFile.Attributes[Constants.CourtFileEntity.Attributes.ListingDate];
//// timeofService = dateOfService.ToLongTimeString();
////}
////else
////{
dateOfService = DateTime.Now;
timeofService = dateOfService.ToLongTimeString();
////}
workingDocumentCollection.DateOfService = string.Format(
CultureInfo.CurrentCulture,
"{0}/{1}/{2}",
dateOfService.Day,
dateOfService.Month,
dateOfService.Year);
//// Get Case - Attaching Documents
workingDocumentCollection.TimeOfService = timeofService;
//LogException(crmHelper._service, "UpdateCourtFile", $"courtFile::{courtFile.Id} workingDocumentCollection_ClaimType::{workingDocumentCollection.ClaimType}", "BusinessLogic", new Exception());
workingDocumentEntityCollection = GetWorkingDocList(courtFile, crmHelper);
if (workingDocumentEntityCollection != null && workingDocumentEntityCollection.Entities.Count > 0)
{
//// List all the Attaching Documents
workingDocumentList.AddRange(from workingDocumentEntity in workingDocumentEntityCollection.Entities
let workingDocumentModel = new WorkingDocument()
select workingDocumentEntity.MapperOut(workingDocumentModel));
}
if (workingDocumentList.Count > 0)
{
//// Assign the list of working documents to Collection
workingDocumentCollection.DocumentCollection = workingDocumentList;
//MB 2025-03-22: this is where the document type is. trace where its coming from and change it to document title
//// Pattern to match the first _YYYYMMDD_HHMMSS.pdf
//string patterns = @"_[0-9]{7,8}_[0-9]{5,6}";
//// Use Regex.Replace with MatchEvaluator to replace only the first occurrence
//string fileNames = Regex.Replace(workingDocumentCollection.DocumentCollection.FirstOrDefault().DocTitle, patterns + @"$|\.pdf$", match => "", RegexOptions.None);
// Pattern to match the first _YYYYMMDD_HHMMSS.pdf
string pattern = @"_[0-9]{7,8}_[0-9]{5,6}";
// Use Regex.Replace with MatchEvaluator to replace only the first occurrence
string fileName = Regex.Replace(workingDocumentCollection.DocumentCollection.FirstOrDefault().DocTitle, pattern, match => "", RegexOptions.None);
Console.WriteLine("After first regex: " + fileName); // Debugging step
// Ensure we only keep the first ".pdf" and remove everything after
//fileName = Regex.Replace(fileName, @"(\.pdf).*", "$1");
fileName = Regex.Replace(fileName, @"\.pdf", "", RegexOptions.None);
//string results = Regex.Replace((string)courtFile.Attributes[Constants.CourtFileEntity.Attributes.docTitle], pattern, "");
workingDocumentCollection.CourtFileTitle = (string)courtFile.Attributes[Constants.CourtFileEntity.Attributes.docTitle];
workingDocumentCollection.ClaimType = fileName;// + DateTime.Now.ToString("yyyyMMddhhmmssfff");
//// Call Azure API here
DocManagementHelper apiHelper = new DocManagementHelper(crmHelper);
DispatcherRequest disp = new DispatcherRequest
{
Operation = Constants.Setting.GetSharepointPath,
Input = new CommonHelper().SerializeJson(workingDocumentCollection)
};
var input = disp.Input;
// LogException(crmHelper._service, "UpdateWorkingDocumentSharepointUrl", input, Constants.Setting.PluginClass, null);
//MB to work here - call to Aspose here
LogException(crmHelper._service, "AsposeDataForFileAproval", input, "BusinessProcess", new Exception("Test"), message: input);
//// Get the courtFile response from ApproveClaim API
string courtFileDocumentCollect = apiHelper.InvokeDocManagementAPI(disp);
// LogException(crmHelper._service, "AsposeDataForFileAproval-Results", courtFileDocumentCollect, "BusinessProcess", new Exception("Test"), message: courtFileDocumentCollect);
if (!string.IsNullOrEmpty(courtFileDocumentCollect))
{
List<DocManagementAPIResponses> docManagementAPIResponses = helper.DeserializeJson<List<DocManagementAPIResponses>>(courtFileDocumentCollect);
WorkingDocumentCollection coll = new Models.WorkingDocumentCollection();
WorkingDocument doc = new Models.WorkingDocument();
if (docManagementAPIResponses != null && docManagementAPIResponses.Count > 0)
{
doc.SharePointLink = docManagementAPIResponses[0].SharePointURL;
doc.BlobLink = docManagementAPIResponses[0].blobURL;
coll.DocumentCollection = new List<WorkingDocument>();
/*Commenting the below code and adding the logic in newcaselinecontroller-UpdateCourtFileData*/
/* coll.DocumentCollection.Add(doc);
Entity updateEntity = new Entity(Constants.Entities.courtFile);
// Bug 297: Documents "Misfiled" by system
// updateEntity.Id = courtFile.Id;
updateEntity.Id = new Guid(docManagementAPIResponses[0].AcitivityID.ToString());
updateEntity[Constants.CourtFileEntity.Attributes.sharePointUrl] = docManagementAPIResponses[0].SharePointURL;
updateEntity[Constants.CourtFileEntity.Attributes.BlobLink] = coll.DocumentCollection[0].BlobLink;
crmHelper._service.Update(updateEntity);*/
}
}
}
}
}
catch (Exception ex)
{
LogException(crmHelper._service, "UpdateCourtFile-exc", string.Empty, "BusinessProcess", ex, message: ex.Message);
throw;
}
}