Exemplo n.º 1
0
        /// <summary>
        ///     Retrieves all entities from Visma.Net. WARNING: Slow.
        /// </summary>
        /// <returns>List of all entities</returns>
        public virtual async Task <List <T> > All()
        {
            var rsp = await VismaNetApiHelper.GetAll <T>(ApiControllerUri, Authorization);

            rsp.ForEach(x => x.InternalPrepareForUpdate());
            return(rsp);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Retrieves all entities from Visma.Net. WARNING: Slow.
        /// </summary>
        /// <returns>List of all entities</returns>
        public virtual async Task <List <T> > Find(NameValueCollection parameters)
        {
            var rsp = await VismaNetApiHelper.GetAll <T>(ApiControllerUri, Authorization, parameters);

            rsp.ForEach(x => x.InternalPrepareForUpdate());
            return(rsp);
        }
Exemplo n.º 3
0
        public async Task <List <DimensionSegment> > Get(Dimension dimension)
        {
            var dimensions = await VismaNetApiHelper.FetchDimension($"{dimension}", Authorization);

            dimensions.ForEach(x => x.PrepareForUpdate());
            return(dimensions);
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Retrieves a single entity by its entity number
        /// </summary>
        /// <param name="entityNumber">Entity number from Visma.Net</param>
        /// <returns>T</returns>
        public virtual async Task <T> Get(string entityNumber)
        {
            var rsp = await VismaNetApiHelper.Get <T>(entityNumber, ApiControllerUri, Authorization);

            rsp.InternalPrepareForUpdate();
            return(rsp);
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Retrieves all entities from Visma.Net. WARNING: Slow.
        /// </summary>
        /// <returns>List of all entities</returns>
        public async Task <List <Location> > All(string baccountId)
        {
            var all = await VismaNetApiHelper.GetAll <Location>($"{VismaNetControllers.Location}/{baccountId}", Authorization);

            all.ForEach(x => x.PrepareForUpdate());
            return(all);
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Creates a new entity
        /// </summary>
        /// <param name="entity">Entity to create</param>
        /// <returns>The created entity from Visma.Net</returns>
        public virtual async Task <Location> Add(Location entity)
        {
            var rsp = await VismaNetApiHelper.Create(entity, ApiControllerUri, Authorization);

            rsp.InternalPrepareForUpdate();
            return(rsp);
        }
        /// <summary>
        ///     AddLarge Invoice entity runs invoicerows in first POST 500 lines then PUT:s in batches of 500 lines
        /// </summary>
        public async Task <CustomerInvoice> AddLarge(CustomerInvoice entity)
        {
            CustomerInvoice            rsp        = null;
            bool                       firstbatch = true;
            List <CustomerInvoiceLine> AllLines   = new List <CustomerInvoiceLine>();

            AllLines.AddRange(entity.invoiceLines);
            foreach (var lines in AllLines.Batch(500))
            {
                entity.invoiceLines.Clear();
                entity.invoiceLines.AddRange(lines);
                if (firstbatch)
                {
                    rsp = await VismaNetApiHelper.Create(entity, ApiControllerUri, Authorization);

                    rsp.InternalPrepareForUpdate();
                    firstbatch = false;
                }
                else
                {
                    rsp.invoiceLines.Clear();
                    rsp.invoiceLines.AddRange(lines);
                    await VismaNetApiHelper.Update(entity, rsp.GetIdentificator(), ApiControllerUri, Authorization);
                }
            }
            rsp = await Get(rsp.GetIdentificator());

            return(rsp);
        }
Exemplo n.º 8
0
        /// <summary>
        ///     Retrieves a single entity by its entity number
        /// </summary>
        /// <param name="baccountId">baccount ID for whih to fetch locations.</param>
        /// <param name="locationId">location ID for the location to fetch.</param>
        /// <returns>T</returns>
        public async Task <Location> Get(string baccountId, string locationId)
        {
            var rsp = await VismaNetApiHelper.Get <Location>($"{baccountId.Trim()}/{locationId.Trim()}", VismaNetControllers.Location, Authorization);

            rsp.PrepareForUpdate();
            return(rsp);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates a new entity
        /// </summary>
        /// <param name="entity">Entity to create</param>
        /// <returns>The created entity from Visma.Net</returns>
        public virtual async Task <T> AddAsyncTask(T entity)
        {
            var rsp = await VismaNetApiHelper.Create(entity, ApiControllerUri, Authorization);

            rsp.PrepareForUpdate();
            return(rsp);
        }
Exemplo n.º 10
0
        /// <summary>
        ///     Retrieves all entities from Visma.Net. WARNING: Slow.
        /// </summary>
        /// <returns>List of all entities</returns>
        public async Task <List <Location> > Find(string baccountId, NameValueCollection parameters)
        {
            var all = await VismaNetApiHelper.GetAllWithPagination <Location>($"{VismaNetControllers.Location}/{baccountId.Trim()}", Authorization, parameters);

            all.ForEach(x => x.PrepareForUpdate());
            return(all);
        }
Exemplo n.º 11
0
        public override async Task <CustomerCreditNote> Add(CustomerCreditNote entity)
        {
            var rsp = await VismaNetApiHelper.Create(entity, VismaNetControllers.CustomerCreditNoteV2, Authorization);

            rsp.InternalPrepareForUpdate();
            return(rsp);
        }
Exemplo n.º 12
0
 public async Task <List <SupplierPOBalance> > GetBalanceForAll()
 {
     return
         (await
          VismaNetApiHelper.Get <List <SupplierPOBalance> >("pobalance", VismaNetControllers.Suppliers,
                                                            Authorization));
 }
Exemplo n.º 13
0
        private async Task <dynamic> _All(InvokeMemberBinder binder, object[] args)
        {
            if (binder.CallInfo.ArgumentCount != args.Length)
            {
                throw new InvalidArgumentsException("Please use only named arguments (like numberToRead: 5)");
            }
            if (string.IsNullOrEmpty(_endpointName))
            {
                throw new Exception("Endpoint name is missing. You are probably using the dynamic endpoint wrong.");
            }
            NameValueCollection nvc = null;

            if (binder.CallInfo.ArgumentCount > 0)
            {
                nvc = new NameValueCollection();
                foreach (
                    var keyValuePair in
                    binder.CallInfo.ArgumentNames.Select((s, i) => new KeyValuePair <string, string>(s, FormatParameter(args[i])))
                    )
                {
                    nvc.Add(keyValuePair.Key, keyValuePair.Value);
                }
            }
            return(await VismaNetApiHelper.GetAll <JObject>($"{_base}{_endpointName}", _auth, nvc));
        }
Exemplo n.º 14
0
 /// <summary>
 ///     Executes the action on all elements streamed from the API.
 /// </summary>
 /// <param name="action"></param>
 /// <returns></returns>
 public virtual async Task ForEach(Action <T> action)
 {
     await VismaNetApiHelper.ForEach(ApiControllerUri, Authorization, (T obj) =>
     {
         action(obj);
         return(Task.FromResult(true));
     });
 }
Exemplo n.º 15
0
 public async Task <dynamic> Get(string argument)
 {
     if (!string.IsNullOrEmpty(argument))
     {
         return(await VismaNetApiHelper.Get <JObject>(argument, $"controller/api/v1/{_endpointName}", _auth));
     }
     return(await Task.FromResult(default(dynamic)));
 }
Exemplo n.º 16
0
 /// <summary>
 ///     Executes the action on all elements streamed from the API.
 /// </summary>
 /// <param name="baccountId">baccount ID for whih to fetch locations.</param>
 /// <param name="action"></param>
 /// <returns></returns>
 public async Task ForEach(string baccountId, Action <Location> action)
 {
     await VismaNetApiHelper.ForEach($"{VismaNetControllers.Location}/{baccountId.Trim()}", Authorization, (Location obj) =>
     {
         action(obj);
         return(Task.FromResult(true));
     });
 }
Exemplo n.º 17
0
 public async Task <SupplierPOBalance> GetBalanceFor(string supplierNumber)
 {
     return
         (await
          VismaNetApiHelper.Get <SupplierPOBalance>(
              string.Format("{0}/pobalance", supplierNumber),
              VismaNetControllers.Suppliers,
              Authorization));
 }
Exemplo n.º 18
0
 public async Task <dynamic> Get(string argument = null)
 {
     if (!string.IsNullOrEmpty(argument))
     {
         return(await VismaNetApiHelper.Get <JObject>(argument, $"{_base}{_endpointName}", _auth));
     }
     else
     {
         return(await VismaNetApiHelper.Get <JObject>(argument, $"{_base}{_endpointName}", _auth));
     }
 }
Exemplo n.º 19
0
 public override async Task Update(SupplierInvoice entity)
 {
     if (entity.documentType != SupplierDocumentType.Invoice)
     {
         await VismaNetApiHelper.Update(entity, entity.GetIdentificator(), ApiControllerUri, Authorization, $"{entity.documentType}/{entity.GetIdentificator()}");
     }
     else
     {
         await VismaNetApiHelper.Update(entity, entity.GetIdentificator(), ApiControllerUri, Authorization);
     }
 }
Exemplo n.º 20
0
 public override async Task Update(SalesOrder entity)
 {
     if (entity.orderType != "SO") // SO ordertypes are special.
     {
         await VismaNetApiHelper.Update(entity, entity.GetIdentificator(), ApiControllerUri, Authorization, $"{entity.orderType}/{entity.GetIdentificator()}");
     }
     else
     {
         await VismaNetApiHelper.Update(entity, entity.GetIdentificator(), ApiControllerUri, Authorization);
     }
 }
Exemplo n.º 21
0
 public async Task <string> AddAttachmentToCreditNote(string creditNoteNumber, byte[] byteArray, string fileName)
 {
     if (byteArray == default(byte[]))
     {
         throw new ArgumentNullException(nameof(byteArray), "ByteArray is missing");
     }
     if (string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(Path.GetExtension(fileName)))
     {
         throw new ArgumentNullException(nameof(fileName), "File name must be provided and have an extention");
     }
     return(await VismaNetApiHelper.AddAttachmentToCreditNote(Authorization, creditNoteNumber, byteArray, fileName));
 }
Exemplo n.º 22
0
 public async Task <string> AddAttachmentToJournalTransaction(string batchNumber, byte[] byteArray, string fileName, JournalTransactionModule module = JournalTransactionModule.ModuleGL)
 {
     if (byteArray == default(byte[]))
     {
         throw new ArgumentNullException(nameof(byteArray), "ByteArray is missing");
     }
     if (string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(Path.GetExtension(fileName)))
     {
         throw new ArgumentNullException(nameof(fileName), "File name must be provided and have an extention");
     }
     return(await VismaNetApiHelper.AddAttachmentToJournalTransaction(Authorization, batchNumber, byteArray, fileName, module));
 }
Exemplo n.º 23
0
        /// <summary>
        /// Retrieves all entities from Visma.Net. WARNING: Slow.
        /// </summary>
        /// <returns>List of all entities</returns>
        public virtual async Task <List <T> > FindAsyncTask(object parameters)
        {
            var formFields = new NameValueCollection();

            parameters.GetType().GetProperties()
            .ToList()
            .ForEach(pi => formFields.Add(pi.Name, pi.GetValue(parameters, null).ToString()));
            var rsp = await VismaNetApiHelper.GetAll <T>(ApiControllerUri, Authorization, formFields);

            rsp.ForEach(x => x.InternalPrepareForUpdate());
            return(rsp);
        }
Exemplo n.º 24
0
 public async Task <string> AddAttachmentToInvoice(string invoiceNumber, Stream stream, string fileName)
 {
     if (stream == default(Stream))
     {
         throw new ArgumentNullException(nameof(stream), "Stream is missing");
     }
     if (string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(Path.GetExtension(fileName)))
     {
         throw new ArgumentNullException(nameof(fileName), "File name must be provided and have an extention");
     }
     return(await VismaNetApiHelper.AddAttachmentToInvoice(Authorization, invoiceNumber, stream, fileName));
 }
Exemplo n.º 25
0
        public async Task <CustomerInvoice> AddLarge(CustomerInvoice entity)
        {
            CustomerInvoice rsp = null;

            System.Diagnostics.Trace.TraceInformation($"Starting post AddLarge CustomerInvoice {DateTime.Now.ToString()}");
            rsp = await VismaNetApiHelper.Create(entity, VismaNetControllers.CustomerInvoiceV2, Authorization, ApiControllerUri);

            System.Diagnostics.Trace.TraceInformation($"Finished post AddLarge CustomerInvoice {DateTime.Now.ToString()}");
            rsp.InternalPrepareForUpdate();

            //rsp = await Get(rsp.GetIdentificator());
            return(rsp);
        }
Exemplo n.º 26
0
        public async Task <SalesOrder> Get(string entityNumber, string orderType = null)
        {
            SalesOrder rsp;

            if (orderType == null || orderType == "SO") // SO ordertypes are special.
            {
                rsp = await VismaNetApiHelper.Get <SalesOrder>(entityNumber, ApiControllerUri, Authorization);
            }
            else
            {
                rsp = await VismaNetApiHelper.Get <SalesOrder>(entityNumber, ApiControllerUri, Authorization, $"{orderType}/{entityNumber}");
            }
            rsp.InternalPrepareForUpdate();
            return(rsp);
        }
Exemplo n.º 27
0
        public override async Task <SalesOrder> Add(SalesOrder entity)
        {
            SalesOrder rsp;

            if (entity.orderType != "SO")
            {
                rsp = await VismaNetApiHelper.Create(entity, ApiControllerUri, Authorization, $"{ApiControllerUri}/{entity.orderType}");
            }
            else
            {
                rsp = await VismaNetApiHelper.Create(entity, ApiControllerUri, Authorization);
            }
            rsp.InternalPrepareForUpdate();
            return(rsp);
        }
Exemplo n.º 28
0
        public async Task <SupplierInvoice> Get(string entityNumber, SupplierDocumentType documentType = SupplierDocumentType.Invoice)
        {
            SupplierInvoice rsp;

            if (documentType == SupplierDocumentType.Invoice) // documentType = invoice use default endpoint.
            {
                rsp = await VismaNetApiHelper.Get <SupplierInvoice>(entityNumber, ApiControllerUri, Authorization);
            }
            else
            {
                rsp = await VismaNetApiHelper.Get <SupplierInvoice>(entityNumber, ApiControllerUri, Authorization, $"{documentType.ToString()}/{entityNumber}");
            }
            rsp.InternalPrepareForUpdate();
            return(rsp);
        }
Exemplo n.º 29
0
        public override async Task <SupplierInvoice> Add(SupplierInvoice entity)
        {
            SupplierInvoice rsp;

            if (entity.documentType != SupplierDocumentType.Invoice)
            {
                rsp = await VismaNetApiHelper.Create(entity, ApiControllerUri, Authorization, $"{ApiControllerUri}/{entity.documentType}");
            }
            else
            {
                rsp = await VismaNetApiHelper.Create(entity, ApiControllerUri, Authorization);
            }
            rsp.InternalPrepareForUpdate();
            return(rsp);
        }
Exemplo n.º 30
0
 public async Task <string> AddAttachmentToInvoice(string invoiceNumber, byte[] byteArray, string fileName, SupplierDocumentType documentType = SupplierDocumentType.Invoice)
 {
     if (byteArray == default(byte[]))
     {
         throw new ArgumentNullException(nameof(byteArray), "ByteArray is missing");
     }
     if (string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(Path.GetExtension(fileName)))
     {
         throw new ArgumentNullException(nameof(fileName), "File name must be provided and have an extention");
     }
     if (documentType != SupplierDocumentType.Invoice)
     {
         invoiceNumber = $"documentType/{documentType}/{invoiceNumber}";
     }
     return(await VismaNetApiHelper.AddAttachmentToSupplierInvoice(Authorization, invoiceNumber, byteArray, fileName));
 }