예제 #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
        /// <summary>
        /// Updates asynchronously the specified subject.
        /// </summary>
        /// <param name="entity">The subject to update.</param>
        /// <returns>Instance of <see cref="JsonSubject"/> class with modified entity.</returns>
        /// <exception cref="ArgumentNullException">entity</exception>
        public async Task <JsonSubject> UpdateAsync(JsonSubject entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            return(await base.UpdateSingleEntityAsync(string.Format("subjects/{0}.json", entity.id), entity));
        }
예제 #3
0
        /// <summary>
        /// Updates the specified subject.
        /// </summary>
        /// <param name="entity">The subject to update.</param>
        /// <returns>Instance of <see cref="JsonSubject"/> class with modified entity.</returns>
        /// <exception cref="ArgumentNullException">entity</exception>
        public JsonSubject Update(JsonSubject entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            return(base.UpdateSingleEntity(string.Format("subjects/{0}.json", entity.id), entity));
        }
예제 #4
0
        /// <summary>
        /// Creates asynchronously the specified new subject.
        /// </summary>
        /// <param name="entity">The new subject.</param>
        /// <returns>ID of newly created subject.</returns>
        /// <exception cref="ArgumentNullException">entity</exception>
        public async Task <int> CreateAsync(JsonSubject entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            return(await base.CreateEntityAsync("subjects.json", entity));
        }
예제 #5
0
        /// <summary>
        /// Creates the specified new subject.
        /// </summary>
        /// <param name="entity">The new subject.</param>
        /// <returns>ID of newly created subject.</returns>
        /// <exception cref="ArgumentNullException">entity</exception>
        public int Create(JsonSubject entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            return(base.CreateEntity("subjects.json", entity));
        }
        /// <summary>
        /// Updates the specified subject.
        /// </summary>
        /// <param name="entity">The subject to update.</param>
        /// <returns>Instance of <see cref="JsonSubject"/> class with modified entity.</returns>
        /// <exception cref="System.ArgumentNullException">entity</exception>
        public JsonSubject Update(JsonSubject entity)
        {
            if (entity == null) throw new ArgumentNullException("entity");

            return base.UpdateSingleEntity(string.Format("subjects/{0}.json", entity.id), entity);
        }
        /// <summary>
        /// Creates the specified new subject.
        /// </summary>
        /// <param name="entity">The new subject.</param>
        /// <returns>ID of newly created subject.</returns>
        /// <exception cref="System.ArgumentNullException">entity</exception>
        public int Create(JsonSubject entity)
        {
            if (entity == null) throw new ArgumentNullException("entity");

            return base.CreateEntity("subjects.json", entity);
        }
        /// <summary>
        /// Updates asynchronously the specified subject.
        /// </summary>
        /// <param name="entity">The subject to update.</param>
        /// <returns>Instance of <see cref="JsonSubject"/> class with modified entity.</returns>
        /// <exception cref="ArgumentNullException">entity</exception>
        public async Task<JsonSubject> UpdateAsync(JsonSubject entity) {
            if (entity == null) throw new ArgumentNullException(nameof(entity));

            return await base.UpdateSingleEntityAsync(string.Format("subjects/{0}.json", entity.id), entity);
        }
        /// <summary>
        /// Creates asynchronously the specified new subject.
        /// </summary>
        /// <param name="entity">The new subject.</param>
        /// <returns>ID of newly created subject.</returns>
        /// <exception cref="ArgumentNullException">entity</exception>
        public async Task<int> CreateAsync(JsonSubject entity) {
            if (entity == null) throw new ArgumentNullException(nameof(entity));

            return await base.CreateEntityAsync("subjects.json", entity);
        }
예제 #10
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();
        }