Пример #1
0
        public async Task <Guid> Handle(CriarComandaCommand request, CancellationToken cancellationToken)
        {
            try
            {
                if (!request.IsValid())
                {
                    ValidationErrors(request);
                    return(await Task.FromResult(Guid.Empty));
                }

                var comanda = new Comanda
                {
                    DataCriacao = DateTime.Now,
                    Mesa        = request.Mesa,
                    Status      = Status.Pendente,
                    Id          = GeradorGuidService.GetNexGuid()
                };

                _comandaRepository.Add(comanda);

                return(await Task.FromResult(comanda.Id));
            }
            catch (Exception ex)
            {
                await Mediator.Publish(new DomainNotification(request.MessageType, $"Erro: {ex.Message}"), cancellationToken);

                return(await Task.FromResult(Guid.Empty));
            }
        }
        public async Task <Guid> Handle(CriarComandaCommand request, CancellationToken cancellationToken)
        {
            var comanda = new Comanda(request.NumeroComanda);

            if (_comandaRepository.PossuiNumeroComandaCadastrada(comanda))
            {
                comanda.AddNotification("Comanda.Numero", "O numero da comanda ja esta cadastrado no banco.");
            }

            if (comanda.Invalid)
            {
                await _mediator.Publish(new DomainNotification
                {
                    Erros = comanda.Notifications
                }, cancellationToken);

                return(await Task.FromResult(Guid.Empty));
            }

            _comandaRepository.Add(comanda);

            return(await Task.FromResult(comanda.Id));
        }
 public void Add(ComandaCreateDTO comandaDTO)
 {
     var comanda = _mapper.Map<ComandaCreateDTO, Comanda>(comandaDTO);
     _comandaRepository.Add(comanda);
 }