Example #1
0
        public async Task <int> Handle(CreateTipoProdutoCommand command, CancellationToken cancellationToken)
        {
            var entity = _mapper.Map <TipoProduto>(command);

            _context.TiposProduto.Add(entity);
            await _context.SaveChangesAsync();

            return(entity.Id);
        }
Example #2
0
        public async Task <string> Handle(CreateTanqueCommand command, CancellationToken cancellationToken)
        {
            var entity = _mapper.Map <Tanque>(command);

            _context.Tanques.Add(entity);
            await _context.SaveChangesAsync();

            return(entity.Deposito);
        }
Example #3
0
        public async Task <int> Handle(UpdateTipoProdutoCommand command, CancellationToken cancellationToken)
        {
            try
            {
                var entity = _context.TiposProduto.Find(command.Id);
                _mapper.Map(command, entity);
                await _context.SaveChangesAsync();

                return(entity.Id);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Example #4
0
        public async Task <string> Handle(UpdateTanqueCommand command, CancellationToken cancellationToken)
        {
            try
            {
                var entity = _context.Tanques.Find(command.Deposito);
                _mapper.Map(command, entity);
                await _context.SaveChangesAsync();

                return(entity.Deposito);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Example #5
0
        public async Task <Unit> Handle(DeleteTanqueCommand command, CancellationToken cancellationToken)
        {
            try
            {
                var entity = _context.Tanques.Find(command.Deposito);
                _context.Tanques.Remove(entity);
                await _context.SaveChangesAsync();

                return(Unit.Value);
            }
            catch (Exception e)
            {
                throw e;
            }
        }