当前位置: 首页>>代码示例>>C#>>正文


C# Repository.UpdateOrCreate方法代码示例

本文整理汇总了C#中Repository.UpdateOrCreate方法的典型用法代码示例。如果您正苦于以下问题:C# Repository.UpdateOrCreate方法的具体用法?C# Repository.UpdateOrCreate怎么用?C# Repository.UpdateOrCreate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Repository的用法示例。


在下文中一共展示了Repository.UpdateOrCreate方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: it_can_UpdateOrCreate_a_model_that_represents_a_valid_endpoint

        public void it_can_UpdateOrCreate_a_model_that_represents_a_valid_endpoint()
        {
            var integrationProxy = new Stubs.StubIntegrationProxy();

            Repository repository = new Repository(integrationProxy);

            repository.UpdateOrCreate(new Invoice());

            Assert.AreEqual("Invoice", integrationProxy.LastEndpointName);
        }
开发者ID:narent,项目名称:XeroAPI.Net,代码行数:10,代码来源:RepositoryTests.cs

示例2: TestCreatingAndUpdatingContacts

        private static void TestCreatingAndUpdatingContacts(Repository repository)
        {
            // Make a PUT call to the API - add a dummy contact
            var contact = new Contact { Name = TestContactName };

            contact = repository.UpdateOrCreate(contact);
            Console.WriteLine(string.Format("The contact '{0}' was created with id: {1}", contact.Name, contact.ContactID));
            Console.WriteLine(string.Format("The validation status was: {0}", contact.ValidationStatus));


            // Try to update the contact that's just been created, but this time use a POST method
            contact.EmailAddress = string.Format("{0}@nowhere.com", contact.Name.ToLower().Replace(" ", "."));

            contact = repository.UpdateOrCreate(contact);
            Console.WriteLine(string.Format("The contact '{0}' was updated with email address: {1}", contact.Name, contact.EmailAddress));
            
            // Get the contact by it's Id...
            var reReadContact = repository.Contacts.First(c => c.ContactID == contact.ContactID);
            Console.WriteLine(string.Format("The contact '{0}' was re-read using it's ContactID: {1}", reReadContact.Name, reReadContact.ContactID));
        }
开发者ID:harry-cs20,项目名称:XeroAPI.Net,代码行数:20,代码来源:Program.cs

示例3: ExerciseOrganisation

        static void ExerciseOrganisation(Repository repository)
        {
            if (repository == null)
            {
                return;
            }

            // Make a call to api.xero.com to check that we can use the access token.
            Organisation organisation = repository.Organisation;
            Console.WriteLine(string.Format("You have been authorised against organisation: {0}", organisation.Name));

            

            // Make a PUT call to the API - add a dummy contact
            Console.WriteLine("Please enter the name of a new contact to add to Xero");
            string contactName = Console.ReadLine();

            if (string.IsNullOrEmpty(contactName))
            {
                return;
            }
            
            Contact contact = new Contact { Name = contactName };
            
            contact = repository.UpdateOrCreate(contact);
            Console.WriteLine(string.Format("The contact '{0}' was created with id: {1}", contact.Name, contact.ContactID));
            Console.WriteLine(string.Format("The validation status was: {0}", contact.ValidationStatus));

            


            // Try to update the contact that's just been created, but this time use a POST method
            contact.EmailAddress = string.Format("{0}@nowhere.com", contact.Name.ToLower().Replace(" ", "."));
            
            contact = repository.UpdateOrCreate(contact);
            Console.WriteLine(string.Format("The contact '{0}' was updated with email address: {1}", contact.Name, contact.EmailAddress));

            

            // Get the contact by it's Id...
            var reReadContact = repository.Contacts.First(c => c.ContactID == contact.ContactID);
            Console.WriteLine(string.Format("The contact '{0}' was re-read using it's ContactID: {1}", reReadContact.Name, reReadContact.ContactID));



            // Construct a linq expression to call 'GET Contacts'...
            int invoiceCount = repository.Contacts
                .Where(c => c.UpdatedDateUTC >= DateTime.UtcNow.AddMonths(-1))
                .Count();

            Console.WriteLine(string.Format("There were {0} contacts created or updated in the last month.", invoiceCount));


            // Construct a linq expression to call 'GET Contacts'...
            var customers = repository.Contacts.Where(c => c.IsCustomer == true).ToList();

            Console.WriteLine(string.Format("There are {0} contacts that are customers.", customers.Count));

            if (customers.Any(c => !c.IsCustomer))
            {
                Console.WriteLine("Filtering contacts on the IsCustomer flag didn't work!");
            }



            // Try out the 'Single' linq method (http://answers.xero.com/developer/question/36501/)
            var organisation2 = repository.Organisations.Single();

            


            // Find out how many bank accounts are defined for the organisation...
            var bankAccounts = repository.Accounts
                .Where(account => account.Type == "BANK")
                .OrderBy(account => account.Name)
                .ToList();

            Console.WriteLine(string.Format("There were {0} bank accounts in this organisation.", bankAccounts.Count()));

            foreach (var bankAaccount in bankAccounts)
            {
                Console.WriteLine(string.Format("Bank Account Name:{0} Code:{1} Number:{2}", bankAaccount.Name, bankAaccount.Code, bankAaccount.BankAccountNumber));
            }




            // Get the tracking categories in this org
            IQueryable<TrackingCategory> trackingCategories = repository.TrackingCategories;

            foreach (var trackingCategory in trackingCategories)
            {
                Console.WriteLine(string.Format("Tracking Category: {0}", trackingCategory.Name));

                foreach (var trackingOption in trackingCategory.Options)
                {
                    Console.WriteLine(string.Format("    Option: {0}", trackingOption.Name));
                }
            }

//.........这里部分代码省略.........
开发者ID:bittercoder,项目名称:XeroAPI.Net,代码行数:101,代码来源:Program.cs

示例4: TestAlteringTrackingAndAccountForApprovedInvoiceWithPayments

		private static void TestAlteringTrackingAndAccountForApprovedInvoiceWithPayments( Repository repository )
		{
			return;

			string invoiceId = "8dc3aeda-dab1-41a3-aa9a-0d9df02ae308";
			Account salesAccount = repository.Accounts.First( w => w.Code == "200" );
			Account otherRevenueAccount = repository.Accounts.First( w => w.Code == "260" );
			List<TrackingCategory> trackingCategories = repository.TrackingCategories.ToList( );
			Invoice approvalInvoice = repository.Invoices.First( f => f.InvoiceID == new Guid( invoiceId ) );
			LineItem firstLine = approvalInvoice.LineItems.First( );

			Console.WriteLine( "Current account is: {0}", firstLine.AccountCode );
			Console.WriteLine( "Current tracking option is: {0}", firstLine.Tracking.Any( ) ? firstLine.Tracking.First( ).Name : " - " );

			firstLine.AccountCode = firstLine.AccountCode == salesAccount.Code ? otherRevenueAccount.Code : salesAccount.Code;
		
			Invoice result = repository.UpdateOrCreate( approvalInvoice );
			if ( result.ValidationErrors.Any( ) )
			{
				Console.WriteLine( "Something went wrong: {0}", result.ValidationErrors.First( ).Message );
			}
			else
			{
				Console.WriteLine( "Updated account is: {0}", firstLine.AccountCode );
				Console.WriteLine( "Updated tracking option is: {0}", firstLine.Tracking.Any( ) ? firstLine.Tracking.First( ).Name : " - " );
			}
		}
开发者ID:TDaphneB,项目名称:XeroAPI.Net,代码行数:27,代码来源:Program.cs

示例5: TestCreatingInvoiceAsSubmittedForApproval

		private static void TestCreatingInvoiceAsSubmittedForApproval( Repository repository )
		{
			// Try and create an invoice - but using incorrect data. This should hopefully be rejected by the Xero API
			Invoice invoiceToCreate = new Invoice
			{
				Contact = new Contact
				{
					Name = TestContactName
				},
				Type = "ACCREC",
				Date = DateTime.Today,
				Status = "SUBMITTED",
				LineItems = new LineItems
                        {
                            new LineItem
                                {
                                    AccountCode = "200",
                                    Description = "Blue Widget",
                                    UnitAmount = 10,
									Quantity = 1
                                }
                        },
				DueDate = DateTime.Now
			};

			Console.WriteLine( "Creating an invoice as submitted..." );
			var createdInvoice = repository.Create( invoiceToCreate );

			if ( createdInvoice.ValidationStatus == ValidationStatus.ERROR )
			{
				foreach ( var message in createdInvoice.ValidationErrors )
				{
					Console.WriteLine( "Validation Error: " + message.Message );
				}
			}
			else
			{
				// Now try to approve it.
				Console.WriteLine( "Approving submitted invoice" );
				createdInvoice.Status = "AUTHORISED";
				createdInvoice = repository.UpdateOrCreate( createdInvoice );

			}
		}
开发者ID:TDaphneB,项目名称:XeroAPI.Net,代码行数:44,代码来源:Program.cs

示例6: TestAlteringAwaitingApprovalInvoice

		private static void TestAlteringAwaitingApprovalInvoice( Repository repository )
		{
			return;

			string invoiceId = "4e59465a-d106-4f13-a9e7-8729fb8842d5";
			Invoice awaitingApprovalInvoice = repository.Invoices.First( f => f.InvoiceID == new Guid( invoiceId ) );
			LineItem firstLine = awaitingApprovalInvoice.LineItems.First( );

			Console.WriteLine( "Current invoice total: {0}", awaitingApprovalInvoice.Total );

			awaitingApprovalInvoice.LineItems.Add( new LineItem( )
			{
				Description = "Alter is successful!!!",
				AccountCode = firstLine.AccountCode,
				Quantity = 1,
				UnitAmount = 10,
				TaxType = firstLine.TaxType
			} );

			Invoice result = repository.UpdateOrCreate( awaitingApprovalInvoice );

			if ( result.ValidationErrors.Any( ) )
			{
				Console.WriteLine( "Something went wrong: {0}", result.ValidationErrors.First( ).Message );
			}
			else
			{
				Console.WriteLine( "No errors, the invoice total is now: {0}", result.Total );
			}
		}
开发者ID:TDaphneB,项目名称:XeroAPI.Net,代码行数:30,代码来源:Program.cs

示例7: TestAlteringApprovedInvoiceWithNoPaymentsOrAllocations

		private static void TestAlteringApprovedInvoiceWithNoPaymentsOrAllocations( Repository repository )
		{
			return; 

			string invoiceId = "7d5aa7cc-3b84-45f7-872f-50d1521ad347";
			Invoice approvalInvoice = repository.Invoices.First( f => f.InvoiceID == new Guid( invoiceId ) );
			LineItem firstLine = approvalInvoice.LineItems.First( );

			Console.WriteLine( "Current invoice total: {0}", approvalInvoice.Total );

			// Add a line
			approvalInvoice.LineItems.Add( new LineItem( )
			{
				Description = "Alter is successful!!!",
				AccountCode = firstLine.AccountCode,
				Quantity = 1,
				UnitAmount = 10,
				TaxType = firstLine.TaxType
			} );

			// Update a line
			firstLine.Quantity = firstLine.Quantity + 1;
			firstLine.LineAmount = null; // nullify so recalculated 

			Invoice result = repository.UpdateOrCreate( approvalInvoice );

			if ( result.ValidationErrors.Any( ) )
			{
				Console.WriteLine( "Something went wrong: {0}", result.ValidationErrors.First( ).Message );
			}
			else
			{
				Console.WriteLine( "No errors, the invoice total is now: {0}", result.Total );
			}
		}
开发者ID:TDaphneB,项目名称:XeroAPI.Net,代码行数:35,代码来源:Program.cs


注:本文中的Repository.UpdateOrCreate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。