/// <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); }
/// <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); }
public async Task <List <DimensionSegment> > Get(Dimension dimension) { var dimensions = await VismaNetApiHelper.FetchDimension($"{dimension}", Authorization); dimensions.ForEach(x => x.PrepareForUpdate()); return(dimensions); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
public override async Task <CustomerCreditNote> Add(CustomerCreditNote entity) { var rsp = await VismaNetApiHelper.Create(entity, VismaNetControllers.CustomerCreditNoteV2, Authorization); rsp.InternalPrepareForUpdate(); return(rsp); }
public async Task <List <SupplierPOBalance> > GetBalanceForAll() { return (await VismaNetApiHelper.Get <List <SupplierPOBalance> >("pobalance", VismaNetControllers.Suppliers, Authorization)); }
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)); }
/// <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)); }); }
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))); }
/// <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)); }); }
public async Task <SupplierPOBalance> GetBalanceFor(string supplierNumber) { return (await VismaNetApiHelper.Get <SupplierPOBalance>( string.Format("{0}/pobalance", supplierNumber), VismaNetControllers.Suppliers, Authorization)); }
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)); } }
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); } }
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); } }
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)); }
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)); }
/// <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); }
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)); }
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); }
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); }
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); }
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); }
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); }
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)); }