示例#1
0
 private static void ImportContacts()
 {
     Console.WriteLine("Importing contacts:");
     subjectIdMap = new Dictionary <int, int>();
     using (var dc = new InvoicingEntities()) {
         foreach (var c in dc.Contacts)
         {
             try {
                 Console.Write("  #{0}: {1}...", c.ContactId, c.CompanyName);
                 var newSubject = new JsonSubject {
                     bank_account    = c.BankAccountNumber,
                     city            = c.DefaultBillAddress.City,
                     country         = c.DefaultBillAddress.Country,
                     custom_id       = c.ContactId.ToString(),
                     email           = c.ContactEmail,
                     full_name       = c.ContactName,
                     name            = c.CompanyName,
                     phone           = c.ContactMobile,
                     registration_no = c.ICO,
                     street          = c.DefaultBillAddress.Street,
                     vat_no          = c.DIC,
                     zip             = c.DefaultBillAddress.ZIP
                 };
                 var newId = context.Subjects.Create(newSubject);
                 Console.WriteLine("OK, ID={0}", newId);
                 subjectIdMap.Add(c.ContactId, newId);
             }
             catch (FakturoidException) {
                 Console.WriteLine("Failed!");
             }
         }
     }
 }
示例#2
0
        private static void ShowSubjects()
        {
            Console.Write("Creating new subject...");
            var subject = new JsonSubject {
                name            = "Altairis, s. r. o.",
                street          = "Bořivojova 35",
                city            = "Praha",
                zip             = "17000",
                country         = "CZ",
                registration_no = "27560911",
                vat_no          = "CZ27560911",
            };
            var newId = context.Subjects.Create(subject);

            Console.WriteLine("OK, ID={0}", newId);

            Console.Write("Getting information about newly created subject...");
            subject = context.Subjects.SelectSingle(newId);
            Console.WriteLine("OK, listing properties:");
            subject.DumpProperties(Console.Out, "\t");

            Console.Write("Updating subject...");
            subject.custom_id = "MY_CUSTOM_ID";
            subject           = context.Subjects.Update(subject);
            Console.WriteLine("OK, listing properties:");
            subject.DumpProperties(Console.Out, "\t");

            try {
                Console.Write("Causing intentional error...");
                context.Subjects.Create(subject);
                Console.WriteLine("OK (that's unexpected!)");
            }
            catch (FakturoidException fex) {
                Console.WriteLine("Failed! (that's expected)");
                Console.WriteLine(fex.Message);
                foreach (var item in fex.Errors)
                {
                    Console.WriteLine("\tProperty '{0}': {1}", item.Key, item.Value);
                }
            }

            Console.Write("Deleting newly created contact...");
            context.Subjects.Delete(newId);
            Console.WriteLine("OK");

            Console.WriteLine();
        }
示例#3
0
        private static void ShowSubjects()
        {
            Console.Write("Creating new subject...");
            var subject = new JsonSubject {
                name = "Altairis, s. r. o.",
                street = "Bořivojova 35",
                city = "Praha",
                zip = "17000",
                country = "CZ",
                registration_no = "27560911",
                vat_no = "CZ27560911",
            };
            var newId = context.Subjects.Create(subject);
            Console.WriteLine("OK, ID={0}", newId);

            Console.Write("Getting information about newly created subject...");
            subject = context.Subjects.SelectSingle(newId);
            Console.WriteLine("OK, listing properties:");
            subject.DumpProperties(Console.Out, "\t");

            Console.Write("Updating subject...");
            subject.custom_id = "MY_CUSTOM_ID";
            subject = context.Subjects.Update(subject);
            Console.WriteLine("OK, listing properties:");
            subject.DumpProperties(Console.Out, "\t");

            try {
                Console.Write("Causing intentional error...");
                context.Subjects.Create(subject);
                Console.WriteLine("OK (that's unexpected!)");
            }
            catch (FakturoidException fex) {
                Console.WriteLine("Failed! (that's expected)");
                Console.WriteLine(fex.Message);
                foreach (var item in fex.Errors) {
                    Console.WriteLine("\tProperty '{0}': {1}", item.Key, item.Value);
                }
            }

            Console.Write("Deleting newly created contact...");
            context.Subjects.Delete(newId);
            Console.WriteLine("OK");

            Console.WriteLine();
        }