示例#1
0
        public async Task CreateAsync_ShouldSuccessfullyAddToDatabase()
        {
            // Arrange
            var context        = ApplicationDbContextInMemoryFactory.InitializeContext();
            var tripRepository = new EfDeletableEntityRepository <OrganizedTrip>(context);

            var service    = new OrganizedTripsService(tripRepository);
            var inputModel = new OrganizedTripInputModel();

            inputModel.Name              = "HotelName";
            inputModel.ImageUrl          = "ImageUrl";
            inputModel.Description       = "Description";
            inputModel.DepartureDateTime = new DateTime(2020, 03, 03, 13, 00, 00);
            inputModel.ReturnDateTime    = new DateTime(2020, 03, 03, 13, 30, 00);
            inputModel.DestinationId     = 1;
            inputModel.PricePerPerson    = 0;
            inputModel.HotelId           = 1;
            inputModel.AvailableSeats    = 1;
            inputModel.Transport         = TransportType.Flight;
            inputModel.ReservationType   = ReservationType.OrganizedTrip;

            var expectedResult = 1;

            // Act
            await service.CreateAsync(inputModel);

            var actualResult = tripRepository.All().Count();

            // Assert
            Assert.True(expectedResult == actualResult);
        }
示例#2
0
        public IActionResult Create()
        {
            this.ViewData["DestinationId"] = new SelectList(this.destinationsService.GetAll(), "Id", "Town");
            this.ViewData["HotelId"]       = new SelectList(this.hotelsService.GetAll(), "Id", "Name");
            var inputModel = new OrganizedTripInputModel();

            return(this.View(inputModel));
        }
示例#3
0
        public async Task <IActionResult> Create(OrganizedTripInputModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                this.ViewData["DestinationId"] = new SelectList(this.destinationsService.GetAll(), "Id", "Town", inputModel.DestinationId);
                this.ViewData["HotelId"]       = new SelectList(this.hotelsService.GetAll(), "Id", "Name", inputModel.HotelId);
                return(this.View(inputModel));
            }

            await this.tripsService.CreateAsync(inputModel);

            return(this.RedirectToAction(nameof(this.Index)));
        }
示例#4
0
        public async Task CreateAsync(OrganizedTripInputModel inputModel)
        {
            var trip = new OrganizedTrip
            {
                Name              = inputModel.Name,
                ImageUrl          = inputModel.ImageUrl,
                Description       = inputModel.Description,
                PricePerPerson    = inputModel.PricePerPerson,
                DepartureDateTime = inputModel.DepartureDateTime,
                ReturnDateTime    = inputModel.ReturnDateTime,
                DestinationId     = inputModel.DestinationId,
                HotelId           = inputModel.HotelId,
                AvailableSeats    = inputModel.AvailableSeats,
                Transport         = inputModel.Transport,
                ReservationType   = inputModel.ReservationType,
            };

            await this.organizedTripsRepository.AddAsync(trip);

            await this.organizedTripsRepository.SaveChangesAsync();
        }