public static async System.Threading.Tasks.Task <IEnumerable <Bag> > UpdateBagsAsync(DocumentClient client, IImageRepository imageservice)
        {
            var bagsRepository       = new SearchRepository <Bag>(client, DocumentDBConstants.DatabaseId, DocumentDBConstants.Collections.Bags);
            var updateBagsRepository = new UpdateRepository <Bag>(client, DocumentDBConstants.DatabaseId, DocumentDBConstants.Collections.Bags);
            var bags = await bagsRepository.SearchItemsAsync(bag => bag.ImageId == null && bag.MainID != 165 && bag.MainID != 1193, 50);

            System.Console.WriteLine($"Fetched {bags.Count()} bags");
            var images = await ImportImages2Async(client, bags, imageservice);

            bags.ToList().ForEach(bag => {
                bag.ImageId = images.FirstOrDefault(image => image.Filename == $"{bag.MainID}.jpg")?.Id;
            });

            System.Console.WriteLine($"Attempting to update {bags.Count()} bags");
            var insertCounter = 0;
            await bags.ToList().ForEachAsync(async bag => {
                var bagid = await updateBagsRepository.UpdateItemAsync(bag.Id, bag);
                insertCounter++;
                System.Console.WriteLine($"Update bag: {insertCounter} - {bag.MainID}");
            });

            System.Console.WriteLine($"Completed updateing {insertCounter} bags");

            return(bags);
        }
        public async Task <ICommandResult> ExecuteAsync(UpdateCommand <TViewModel> command)
        {
            var activity = await ActivityRepository.SearchItemsAsync(x => x.Name == $"{typeof(TViewModel)}{nameof(UpdateCommandHandler<UpdateCommand<TViewModel>, TEntity>)}");

            if (await Authorizer.IsAuthorized(activity.FirstOrDefault()))
            {
                return(new ForbidResult());
            }

            if (command.Data == null)
            {
                return(new ErrorResult("Update item cannot be null"));
            }

            var entity = Translator.Translate(command.Data);
            await UpdateRepository.UpdateItemAsync(command.Id, entity);

            return(new OkResult());
        }
        public async Task <ICommandResult> ExecuteAsync(UpdateBagCommand command)
        {
            var activity = await ActivityRepository.SearchItemsAsync(x => x.Name == $"{nameof(UpdateBagCommandHandler)}");

            if (await Authorizer.IsAuthorized(activity.FirstOrDefault()))
            {
                return(new ForbidResult());
            }

            if (command == null)
            {
                return(new ErrorResult("Update item cannot be null"));
            }

            var previousEntity = await GetRepository.GetItemAsync(command.Id);

            var entity = Translator.Translate(command.Data, previousEntity);
            await UpdateRepository.UpdateItemAsync(command.Id, entity);

            return(new OkResult());
        }