Ejemplo n.º 1
0
        public async Task <ActionResult> CreateRentalAsync(
            [FromBody] CreateRentalCommand createRentalCommand,
            CancellationToken cancellationToken)
        {
            await _rentalHandler.CreateRentalAsync(createRentalCommand, cancellationToken);

            return(Ok());
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> PostAsync()
        {
            var command = new CreateRentalCommand(Guid.NewGuid(), Guid.NewGuid(), "Mirek",
                                                  "Kudra", "*****@*****.**",
                                                  Guid.NewGuid(), DateTime.Now);
            await _mediator.Send(command);

            return(Ok());
        }
Ejemplo n.º 3
0
        public async Task CreateRentalAsync(
            CreateRentalCommand createRentalCommand,
            CancellationToken cancellationToken)
        {
            var rental = await _rentalDomainService.CreateRentalAsync(createRentalCommand.UserId, createRentalCommand.Name, cancellationToken);

            await _rentalRepository.CreateAsync(rental, cancellationToken);

            await _rentalRepository.SaveAsync(cancellationToken);
        }
        public async Task <IActionResult> Post([FromBody] CreateRentalRequest request)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var       command = new CreateRentalCommand(request.PickUpDate, request.DropOffDate, request.CustomerId, request.CarId);
                RentalDTO rental  = await _mediator.Send(command);

                return(Created(string.Empty, rental));
            }
            catch (OException ex)
            {
                return(BadRequest(ex.Message));
            }
        }