Exemplo n.º 1
0
        public async Task <int> Create(Ingredient ingredient)
        {
            _context.Ingredients.Add(ingredient);
            await _context.SaveChangesAsync();

            return(ingredient.Id);
        }
Exemplo n.º 2
0
            public async Task <Ingredient> Handle(Command command, CancellationToken cancellationToken)
            {
                var ingredient =
                    await _context
                    .Ingredients
                    .FirstOrDefaultAsync(s => s.Id == command.Id);

                _context.Ingredients.Remove(ingredient);
                await _context.SaveChangesAsync();

                return(_mapper.Map <Ingredient>(ingredient));
            }
Exemplo n.º 3
0
            public async Task <Ingredient> Handle(Command command, CancellationToken cancellationToken)
            {
                var ingredient = new Data.Entities.SandwichShop.Ingredient
                {
                    Name  = command.Name,
                    Price = command.Price
                };

                _context.Ingredients.Add(ingredient);
                await _context.SaveChangesAsync();

                return(_mapper.Map <Ingredient>(ingredient));
            }
Exemplo n.º 4
0
            public async Task <Ingredient> Handle(Command command, CancellationToken cancellationToken)
            {
                var ingredient =
                    await _context
                    .Ingredients
                    .FirstOrDefaultAsync(s => s.Id == command.Id);

                ingredient.Name  = command.UpdateFields.Name;
                ingredient.Price = command.UpdateFields.Price;

                await _context.SaveChangesAsync();

                return(_mapper.Map <Ingredient>(ingredient));
            }