public async Task <IActionResult> Create(CollectionItemViewModel model)
        {
            var set = await setRepository.UpdateAndGetByNumber(model.SetNumber);

            var setParts = await partOfSetRepository.UpdateAndGetSetParts(set);

            var collectionItem = new CollectionItem
            {
                Name        = set.Name,
                Number      = set.Number,
                DateCreated = DateTime.Now,
                Type        = ProcessType.Created
            };
            await collectionItemRepository.Save(collectionItem);

            //var partIds = setParts.Select(p => p.PartId).ToArray();
            //var parts = await partRepository.Filter(p => partIds.Contains(p.Id));
            var partsOfCollection = setParts
                                    .Where(p => !p.IsCounterpart && !p.IsAlternate)
                                    .Select(p => new PartOfCollectionItem
            {
                PartId           = p.PartId,
                CollectionItemId = collectionItem.Id,
                Condition        = ConditionType.Good,
                Quantity         = p.Quantity,
                //ToDo: do smth with state which could be only taken from PartRepository
                State = StateType.Used
            })
                                    .ToList();
            await partOfCollectionItemRepository.InsertMany(partsOfCollection);

            return(Ok());
        }
        public async Task <IActionResult> GetSetPriceByParts(
            [FromRoute] string setNumber,
            [FromQuery(Name = "state")] StateType stateType,
            [FromQuery(Name = "price")] PriceFormationType priceFormationType
            )
        {
            var set = await setRepository.UpdateAndGetByNumber(setNumber);

            #region Process Set Parts

            var timer = new Stopwatch();
            timer.Start();
            var partsOfSet = await partOfSetRepository.UpdateAndGetSetParts(set);

            var parallelPartsTime = timer.Elapsed;
            timer.Stop();


            decimal sum       = 0;
            var     priceList = new List <(string Number, Color Color, decimal Price)>();


            timer.Restart();
            var selectedParts = partsOfSet.Where(p => !p.IsCounterpart && !p.IsAlternate);
            var parallelTasks = selectedParts.Select(p => ProcessPartPrice(p, stateType, priceFormationType));

            var taskResults = (await Task.WhenAll(parallelTasks))
                              .Where(i => i.Item2 != default)
                              .ToArray();
            priceList.AddRange(taskResults.Select(r => r.Item2));
            sum = taskResults.Sum(i => i.Item1);

            var parallelPricesTime = timer.Elapsed;
            timer.Stop();

            #endregion


            return(Ok(new
            {
                SetNumber = setNumber,
                PriceFormation = priceFormationType.ToString(),
                Sum = sum,
                Detailed = priceList
                           .OrderByDescending(item => item.Price)
                           .Select(p => new { p.Number, p.Color, Price = Math.Round(p.Price, 4) })
                           .ToArray()
            }));
        }