public async Task <CommandResult> HandleAsync(CreateCarReservation command)
        {
            CarReservationEntity carReservation = new CarReservationEntity(command.CarTypeId, command.City,
                                                                           command.PostCode, command.Street,
                                                                           command.PhoneNumber, command.Name,
                                                                           command.GetReservationDate());

            CommandResult result = await _carReservationProcess.MakeReservation(carReservation);

            return(result);
        }
Esempio n. 2
0
        public async Task makereservation_should_invoke_savechanges_on_dbcontext()
        {
            var command = new CreateCarReservation
            {
                City            = "TestCity",
                PostCode        = "57-400",
                Name            = "TestName",
                CarTypeId       = 0,
                PhoneNumber     = "55555555",
                ReservationDate = "2018-08-08",
                Street          = "TestStreet"
            };


            CarReservationEntity carReservation = new CarReservationEntity(command.CarTypeId, command.City
                                                                           , command.PostCode, command.Street, command.PhoneNumber, command.Name, command.GetReservationDate());
            var result = await carReservationProcess.MakeReservation(carReservation);

            mockcontext.Verify(x => x.SaveChangesAsync(), Times.Once);
            Assert.True(result.Success);
        }
        public async Task <CommandResult> MakeReservation(CarReservationEntity carReservation)
        {
            var carType = await _context.CarType
                          .Where(ct => ct.Id == carReservation.CarTypeId)
                          .FirstOrDefaultAsync();

            if (carType == null)
            {
                return new CommandResult
                       {
                           Success = false,
                           Message = "Brak typu pojazdu"
                       }
            }
            ;
            //var carReservation = new CarReservationEntity(carTypeId, city, postCode, street, phoneNumber, name, dateReservation);
            var result = carType.AddCarReservation(carReservation);

            if (result == CreateCarReservationResult.MaxCarPerDayExceeded)
            {
                return new CommandResult
                       {
                           Success = false,
                           Message = $"Typ pojazdu niedostępny w dniu {carReservation.ReservationDate.ToString("yyyy-MM-dd")} "
                       }
            }
            ;
            else
            {
                await _context.SaveChangesAsync();

                return(new CommandResult
                {
                    Success = true,
                    Message = $"Rezerwacja zakończona, dziękujemy"
                });
            }
        }
    }