Exemple #1
0
        public async Task <CollectionWrapper <IngredientModel> > GetByCategoryIdAsync(Guid categoryId, QueryContext context, CancellationToken cancellationToken)
        {
            var result = await Repository.GetAsync(
                x =>
                IncludeFunction(QueryFunctions.IngredientsByCategoryIdFunction(x, categoryId))
                .Paginate(context, y => y.ModifiedDate),
                cancellationToken);

            return(WrapCollection(Mapper.Map <IngredientModel[]>(result), context));
        }
        public async Task <CollectionWrapper <CocktailModel> > GetByCocktailNameAsync(string cocktailName,
                                                                                      QueryContext context, CancellationToken cancellationToken)
        {
            var result = await Repository.GetAsync(
                x =>
                IncludeFunction(QueryFunctions.CocktailsByNameFunction(x, cocktailName))
                .Paginate(context, y => y.ModifiedDate),
                cancellationToken);

            return(WrapCollection(Mapper.Map <CocktailModel[]>(result), context));
        }
        private async Task ProcessMixesAsync(Guid id, CocktailModel model, CancellationToken cancellationToken)
        {
            var mixes = await _mixRepository.GetAsync(x => QueryFunctions.GetByIdFunction <Mix>()(x, id), cancellationToken);

            foreach (var mix in mixes)
            {
                var modelMix = model.Mixes.FirstOrDefault(x => x.IngredientId == mix.IngredientId);
                if (modelMix != null)
                {
                    if (modelMix.Amount != mix.Amount)
                    {
                        mix.Amount = modelMix.Amount;
                        await _mixRepository.UpdateAsync(mix, cancellationToken, false);
                    }
                    model.Mixes.Remove(modelMix);
                }
                else
                {
                    await _mixRepository.DeleteAsync(mix, cancellationToken, false);
                }
            }
        }
Exemple #4
0
        public virtual async Task <TModel> GetByIdAsync(Guid id, CancellationToken cancellationToken)
        {
            var result = await Repository.GetSingleAsync(x => IncludeFunction(QueryFunctions.GetByIdFunction <TEntity>()(x, id)), cancellationToken);

            return(Mapper.Map <TModel>(result));
        }