/// <summary> /// Returns the folder name for a given entity /// </summary> /// <param name="entityName"></param> /// <param name="entityId"></param> /// <param name="getFromDocumentLocation"></param> /// <param name="_dynamicsClient"></param> /// <returns></returns> public static async Task <string> GetFolderName(this IDynamicsClient _dynamicsClient, string entityName, string entityId, bool getFromDocumentLocation = true) { string folderName = null; if (getFromDocumentLocation) { folderName = _dynamicsClient.GetEntitySharePointDocumentLocation(entityName, entityId); } if (folderName == null) { switch (entityName.ToLower()) { case "account": var account = await _dynamicsClient.GetAccountByIdAsync(Guid.Parse(entityId)).ConfigureAwait(true); folderName = account.GetDocumentFolderName(); break; case "application": var application = await _dynamicsClient.GetApplicationById(Guid.Parse(entityId)).ConfigureAwait(true); folderName = application.GetDocumentFolderName(); break; case "contact": var contact = await _dynamicsClient.GetContactById(Guid.Parse(entityId)).ConfigureAwait(true); folderName = contact.GetDocumentFolderName(); break; case "worker": var worker = await _dynamicsClient.GetWorkerById(Guid.Parse(entityId)).ConfigureAwait(true); folderName = worker.GetDocumentFolderName(); break; case "event": var eventEntity = _dynamicsClient.GetEventById(Guid.Parse(entityId)); folderName = eventEntity.GetDocumentFolderName(); break; case "licence": var licenceEntity = _dynamicsClient.GetLicenceById(Guid.Parse(entityId)); folderName = licenceEntity.GetDocumentFolderName(); break; case "specialevent": var entity = _dynamicsClient.GetSpecialEventById(entityId); folderName = entity.GetDocumentFolderName(); break; } } return(folderName); }