Ejemplo n.º 1
0
        public async Task <ICommandResult> Handle(AddPointOfSaleInEventCommand command)
        {
            if (!command.IsValid())
            {
                AddNotifications(command.Notifications);
                return(null);
            }

            var @event = await _eventRepository.GetByIdWithPointOfSaleEvents(command.EventId);

            if (@event.PointOfSaleInEvent(command.PointOfSaleId))
            {
                AddNotification("event", "Ponto de venda já está cadastrado neste evento");
                return(null);
            }

            var pointOfSale = await _pointOfSaleRepository.GetById(command.PointOfSaleId);

            @event.AddPointOfSaleInEvent(pointOfSale);
            await _eventRepository.Commit();

            return(new AddPointOfSaleInEventCommandResult()
            {
                Name = @event.Name,
                StartDate = @event.StartDate.ToShortDateString(),
                EndDate = @event.EndDate.ToShortDateString(),
                Photo = @event.Photo,
                PointOfSale = pointOfSale
            });
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> AddPointOfSaleInEvent(AddPointOfSaleInEventCommand command)
        {
            var result = await _handler.Handle(command);

            if (!_handler.IsValid())
            {
                return(BadRequest(_handler.GetErrors()));
            }

            return(Ok(result));
        }