/// <summary> /// Copy values from View Model to Dynamics legal entity /// </summary> /// <param name="to"></param> /// <param name="from"></param> public static void CopyValues(this Adoxio_legalentity to, ViewModels.AdoxioLegalEntity from, Interfaces.Microsoft.Dynamics.CRM.System _system) { to.Adoxio_commonnonvotingshares = from.commonnonvotingshares; to.Adoxio_commonvotingshares = from.commonvotingshares; to.Adoxio_dateofbirth = from.dateofbirth; to.Adoxio_firstname = from.firstname; to.Adoxio_interestpercentage = from.interestpercentage; to.Adoxio_isindividual = (from.isindividual != null && (bool)from.isindividual) ? 1 : 0; to.Adoxio_lastname = from.lastname; to.Adoxio_legalentitytype = (int?)from.legalentitytype; to.Adoxio_middlename = from.middlename; to.Adoxio_name = from.name; to.Adoxio_ispartner = (from.isPartner == true); to.Adoxio_isshareholder = from.isShareholder; to.Adoxio_istrustee = false; to.Adoxio_isdirector = from.isDirector; to.Adoxio_isofficer = from.isOfficer; to.Adoxio_isowner = false; to.Adoxio_preferrednonvotingshares = from.preferrednonvotingshares; to.Adoxio_preferredvotingshares = from.preferredvotingshares; to.Adoxio_sameasapplyingperson = (from.sameasapplyingperson != null && (bool)from.sameasapplyingperson) ? 1 : 0; to.Adoxio_email = from.email; to.Adoxio_dateofappointment = from.dateofappointment; // Assigning the account this way throws exception: // System.InvalidOperationException: Collection was modified; enumeration operation may not execute. //if (from.account.id != null) //{ // // fetch the account from Dynamics. // var getAccountTask = _system.GetAccountById(null, Guid.Parse(from.account.id)); // getAccountTask.Wait(); // to.Adoxio_Account= getAccountTask.Result; //} // adoxio_dateemailsent }
/// <summary> /// Copy values from a Dynamics legal entity to another one /// </summary> /// <param name="to"></param> /// <param name="from"></param> public static void CopyValues(this Adoxio_legalentity to, Adoxio_legalentity from) { to.Adoxio_legalentityid = from.Adoxio_legalentityid; to.Adoxio_commonnonvotingshares = from.Adoxio_commonnonvotingshares; to.Adoxio_commonvotingshares = from.Adoxio_commonvotingshares; to.Adoxio_dateofbirth = from.Adoxio_dateofbirth; to.Adoxio_firstname = from.Adoxio_firstname; to.Adoxio_interestpercentage = from.Adoxio_interestpercentage; to.Adoxio_isindividual = from.Adoxio_isindividual; to.Adoxio_lastname = from.Adoxio_lastname; to.Adoxio_legalentitytype = from.Adoxio_legalentitytype; to.Adoxio_middlename = from.Adoxio_middlename; to.Adoxio_name = from.Adoxio_name; to.Adoxio_position = from.Adoxio_position; to.Adoxio_ispartner = from.Adoxio_ispartner; to.Adoxio_isshareholder = from.Adoxio_isshareholder; to.Adoxio_istrustee = from.Adoxio_istrustee; to.Adoxio_isdirector = from.Adoxio_isdirector; to.Adoxio_isofficer = from.Adoxio_isofficer; to.Adoxio_isowner = from.Adoxio_isowner; to.Adoxio_preferrednonvotingshares = from.Adoxio_preferrednonvotingshares; to.Adoxio_preferredvotingshares = from.Adoxio_preferredvotingshares; to.Adoxio_sameasapplyingperson = from.Adoxio_sameasapplyingperson; to.Adoxio_dateofappointment = from.Adoxio_dateofappointment; }
/// <summary> /// Convert a legal entity to a model /// </summary> /// <param name="from"></param> /// <returns></returns> public static Adoxio_legalentity ToModel(this ViewModels.AdoxioLegalEntity from) { Adoxio_legalentity result = null; if (from != null) { result = new Adoxio_legalentity(); result.Adoxio_legalentityid = new Guid(from.id); result.Adoxio_commonnonvotingshares = from.commonnonvotingshares; result.Adoxio_commonvotingshares = from.commonvotingshares; result.Adoxio_dateofbirth = from.dateofbirth; result.Adoxio_firstname = from.firstname; result.Adoxio_interestpercentage = from.interestpercentage; result.Adoxio_isindividual = (from.isindividual != null && (bool)from.isindividual) ? 1 : 0; result.Adoxio_lastname = from.lastname; result.Adoxio_legalentitytype = (int?)from.legalentitytype; result.Adoxio_middlename = from.middlename; result.Adoxio_name = from.name; result.Adoxio_ispartner = (from.isPartner == true); result.Adoxio_isshareholder = (from.isShareholder == true); //result.AdoxioIstrustee = from.isTrustee; //result.AdoxioIsowner = from.isOwner; result.Adoxio_isdirector = (from.isDirector == true); result.Adoxio_isofficer = (from.isOfficer == true); result.Adoxio_isseniormanagement = (from.isSeniorManagement == true); result.Adoxio_preferrednonvotingshares = from.preferrednonvotingshares; result.Adoxio_preferredvotingshares = from.preferredvotingshares; result.Adoxio_sameasapplyingperson = (from.sameasapplyingperson != null && (bool)from.sameasapplyingperson) ? 1 : 0; result.Adoxio_dateofappointment = from.dateofappointment; } return(result); }
/// <summary> /// Convert a given voteQuestion to a ViewModel /// </summary> public static ViewModels.AdoxioLegalEntity ToViewModel(this Adoxio_legalentity adoxio_legalentity) { ViewModels.AdoxioLegalEntity result = null; if (adoxio_legalentity != null) { result = new ViewModels.AdoxioLegalEntity(); if (adoxio_legalentity.Adoxio_legalentityid != null) { result.id = adoxio_legalentity.Adoxio_legalentityid.ToString(); } result.isDirector = (adoxio_legalentity.Adoxio_isdirector == true); result.commonnonvotingshares = adoxio_legalentity.Adoxio_commonnonvotingshares; result.commonvotingshares = adoxio_legalentity.Adoxio_commonvotingshares; result.dateofbirth = adoxio_legalentity.Adoxio_dateofbirth; result.firstname = adoxio_legalentity.Adoxio_firstname; result.interestpercentage = adoxio_legalentity.Adoxio_interestpercentage; // convert from int to bool. result.isindividual = (adoxio_legalentity.Adoxio_isindividual != null && adoxio_legalentity.Adoxio_isindividual != 0); result.lastname = adoxio_legalentity.Adoxio_lastname; if (adoxio_legalentity.Adoxio_legalentitytype != null) { result.legalentitytype = (Adoxio_applicanttypecodes)adoxio_legalentity.Adoxio_legalentitytype; } result.middlename = adoxio_legalentity.Adoxio_middlename; result.name = adoxio_legalentity.Adoxio_name; result.email = adoxio_legalentity.Adoxio_email; result.preferrednonvotingshares = adoxio_legalentity.Adoxio_preferrednonvotingshares; result.preferredvotingshares = adoxio_legalentity.Adoxio_preferredvotingshares; // convert from int to bool. result.sameasapplyingperson = (adoxio_legalentity.Adoxio_sameasapplyingperson != null && adoxio_legalentity.Adoxio_sameasapplyingperson != 0); result.dateofappointment = adoxio_legalentity.Adoxio_dateofappointment; // populate the account. if (adoxio_legalentity.Adoxio_Account != null) { result.account = adoxio_legalentity.Adoxio_Account.ToViewModel(); } result.accountId = adoxio_legalentity._adoxio_account_value.ToString(); } return(result); }
public async System.Threading.Tasks.Task TestFileUpload() { // First create a Legal Entity string initialName = randomNewUserName("LETest InitialName", 6); string changedName = randomNewUserName("LETest ChangedName", 6); string service = "adoxiolegalentity"; var loginUser = randomNewUserName("NewLoginUser", 6); var strId = await LoginAndRegisterAsNewUser(loginUser); ViewModels.User user = await GetCurrentUser(); // C - Create var request = new HttpRequestMessage(HttpMethod.Post, "/api/" + service); Adoxio_legalentity adoxio_legalentity = new Adoxio_legalentity() { Adoxio_legalentityid = Guid.NewGuid(), Adoxio_legalentitytype = (int?)ViewModels.Adoxio_applicanttypecodes.PrivateCorporation, Adoxio_position = (int?)ViewModels.PositionOptions.Director, Adoxio_name = initialName }; ViewModels.AdoxioLegalEntity viewmodel_adoxio_legalentity = adoxio_legalentity.ToViewModel(); string jsonString = JsonConvert.SerializeObject(viewmodel_adoxio_legalentity); request.Content = new StringContent(jsonString, Encoding.UTF8, "application/json"); var response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); // parse as JSON. jsonString = await response.Content.ReadAsStringAsync(); ViewModels.AdoxioLegalEntity responseViewModel = JsonConvert.DeserializeObject <ViewModels.AdoxioLegalEntity>(jsonString); // name should match. Assert.Equal(initialName, responseViewModel.name); string id = responseViewModel.id; // Attach a file string testData = "This is just a test."; byte[] bytes = Encoding.ASCII.GetBytes(testData); string documentType = "Test Document Type"; // Create random filename var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; var stringChars = new char[9]; var random = new Random(); for (int i = 0; i < stringChars.Length; i++) { stringChars[i] = chars[random.Next(chars.Length)]; } var randomString = new String(stringChars); string filename = randomString + ".txt"; MultipartFormDataContent multiPartContent = new MultipartFormDataContent("----TestBoundary"); var fileContent = new MultipartContent { new ByteArrayContent(bytes) }; fileContent.Headers.ContentType = new MediaTypeHeaderValue("text/plain"); fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data"); fileContent.Headers.ContentDisposition.Name = "File"; fileContent.Headers.ContentDisposition.FileName = filename; multiPartContent.Add(fileContent); multiPartContent.Add(new StringContent(documentType), "documentType"); // form input string accountId = user.accountid; // create a new request object for the upload, as we will be using multipart form submission. var requestMessage = new HttpRequestMessage(HttpMethod.Post, "/api/" + service + "/" + accountId + "/attachments"); requestMessage.Content = multiPartContent; var uploadResponse = await _client.SendAsync(requestMessage); uploadResponse.EnsureSuccessStatusCode(); // Verify that the file Meta Data matches // Verify that the file can be downloaded and the contents match // Cleanup the Legal Entity request = new HttpRequestMessage(HttpMethod.Post, "/api/" + service + "/" + id + "/delete"); response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); // should get a 404 if we try a get now. request = new HttpRequestMessage(HttpMethod.Get, "/api/" + service + "/" + id); response = await _client.SendAsync(request); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); await LogoutAndCleanupTestUser(strId); }