Work with Memory Collections in Business Central AL

Hello, I'm a beginner in AL coding Business Central. I would like to create a procedure with 2 complex type of collections parameter and the result should be 1 complex type of collection also.I should get  parameters collections from web API, and send back the result via API also. My Question is how can I define these complex type without databasetable and work with them in memory?

I have cretate one sampler code in C#:

class Storage{ 
           public  decimal Quantity { get; set; }

            public string Item { get; set; }
        }

 class Order {
            public int OrderId { get; set; }
            public decimal Quantity { get; set; }
            public string Item { get; set; }
        }

        /// <summary>
        /// Check Sotrage to Summorized Orders
        /// </summary>
        /// <param name="storage">Storgate of Items </param>
        /// <param name="orders">Ordered Items</param>
        /// <returns>List of orders what we can’t complete together</returns>
  List<Order> Calculation(List<Storage> storage, List<Order> orders)
        {
            //Order what I can't complate
            var _result = new List<Order>();

            //Summarized Demand by Item
            var _sumDemands = orders.GroupBy(g => g.Item).Select(s => new Order { Item = s.Key, Quantity = s.Sum(z => z.Quantity) });
            
            foreach (var _demand in _sumDemands)
            {
                //We don't have enough sotrage to complate all of orders 
                // I don't care if I posible to complate one of them 
                if (!storage.Any(s => s.Item == _demand.Item) || storage.FirstOrDefault(s => s.Item == _demand.Item).Quantity < _demand.Quantity)
                {
                    foreach (var _order in orders.Where(w => w.Item == _demand.Item))
                    {
                        _result.Add(_order);
                    }
                }
                        
            }

            return _result;
        }

Thank you!

Gergely

Parents
No Data
Reply Children
No Data
Related
Recommended