Exemplo n.º 1
0
        public IActionResult Create()
        {
            this.ViewData["DestinationId"] = new SelectList(this.destinationsService.GetAll(), "Id", "Town");
            var inputModel = new HotelInputModel();

            return(this.View(inputModel));
        }
        public async Task CreateAsync_ShouldSuccessfullyAddToDatabase()
        {
            // Arrange
            var context         = ApplicationDbContextInMemoryFactory.InitializeContext();
            var hotelRepository = new EfDeletableEntityRepository <Hotel>(context);

            var service    = new HotelsService(hotelRepository);
            var inputModel = new HotelInputModel();

            inputModel.Name                   = "HotelName";
            inputModel.ImageUrl               = "ImageUrl";
            inputModel.Description            = "Description";
            inputModel.Address                = "Adress";
            inputModel.DestinationId          = 1;
            inputModel.PricePerNightPerPerson = 0;
            inputModel.Stars                  = 1;
            inputModel.AvailableRooms         = 1;
            inputModel.FeedingType            = FeedingType.Breakfast;
            inputModel.ReservationType        = ReservationType.Hotel;

            var expectedResult = 1;

            // Act
            await service.CreateAsync(inputModel);

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

            // Assert
            Assert.True(expectedResult == actualResult);
        }
Exemplo n.º 3
0
 public ActionResult EditHotel(int?id)
 {
     if (id != null)
     {
         Hotel           hotel           = db.GetHotel(id.Value);
         HotelInputModel hotelInputModel = new HotelInputModel(hotel);
         return(View(hotelInputModel));
     }
     return(RedirectToAction("ManagementWindow"));
 }
Exemplo n.º 4
0
        public async Task <IActionResult> Create(HotelInputModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                this.ViewData["DestinationId"] = new SelectList(this.destinationsService.GetAll(), "Id", "Town", inputModel.DestinationId);
                return(this.View(inputModel));
            }

            await this.hotelsService.CreateAsync(inputModel);

            return(this.RedirectToAction(nameof(this.Index)));
        }
Exemplo n.º 5
0
 public void ConvertFromInputModel(HotelInputModel hotel)
 {
     Naam                         = hotel.Naam;
     Omschrijving                 = hotel.Omschrijving;
     Adres                        = hotel.Adres;
     PostalCode                   = hotel.PostalCode;
     City                         = hotel.City;
     TelefoonNummer               = hotel.TelefoonNummer;
     Website                      = hotel.Website;
     HotelAfbeelding.Link         = hotel.BannerAfbeelding.Link;
     HotelOverviewAfbeelding.Link = hotel.OverviewAfbeelding.Link;
 }
Exemplo n.º 6
0
 public ActionResult EditHotel(HotelInputModel hotel)
 {
     if (ModelState.IsValid)
     {
         Hotel hotelToEdit = db.GetHotel(hotel.HotelId);
         hotelToEdit.ConvertFromInputModel(hotel);
         db.UpdateHotel(hotelToEdit);
     }
     else
     {
         ModelState.AddModelError("edit-error", "The Hotel you tried to edit had some incorrectly filled fields.");
     }
     return(View(hotel));
 }
Exemplo n.º 7
0
        public ActionResult <HotelViewModel> Post(HotelInputModel hotelInput)
        {
            Hotel hotel    = MapearHotel(hotelInput);
            var   response = _hotelService.Guardar(hotel);

            if (response.Error)
            {
                ModelState.AddModelError("Guardar Hotel", response.Mensaje);
                var problemDetails = new ValidationProblemDetails(ModelState)
                {
                    Status = StatusCodes.Status400BadRequest,
                };
                return(BadRequest(problemDetails));
            }
            return(Ok(response.Hotel));
        }
Exemplo n.º 8
0
        private Hotel MapearHotel(HotelInputModel hotelInput)
        {
            var hotel = new Hotel
            {
                Nit               = hotelInput.Nit,
                Nombre            = hotelInput.Nombre,
                Pais              = hotelInput.Pais,
                Ciudad            = hotelInput.Ciudad,
                Direccion         = hotelInput.Direccion,
                Barrio            = hotelInput.Barrio,
                Telefono          = hotelInput.Telefono,
                CorreoElectronico = hotelInput.CorreoElectronico,
                SitioWeb          = hotelInput.SitioWeb
            };

            return(hotel);
        }
Exemplo n.º 9
0
        public async Task CreateAsync(HotelInputModel inputModel)
        {
            var hotel = new Hotel
            {
                Name                   = inputModel.Name,
                ImageUrl               = inputModel.ImageUrl,
                Description            = inputModel.Description,
                Address                = inputModel.Address,
                DestinationId          = inputModel.DestinationId,
                PricePerNightPerPerson = inputModel.PricePerNightPerPerson,
                Stars                  = inputModel.Stars,
                AvailableRooms         = inputModel.AvailableRooms,
                ReservationType        = inputModel.ReservationType,
                FeedingType            = inputModel.FeedingType,
            };

            await this.hotelsRepository.AddAsync(hotel);

            await this.hotelsRepository.SaveChangesAsync();
        }
Exemplo n.º 10
0
        public ActionResult Create(HotelInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return this.View(model);
            }

            var hotel = this.Mapper.Map<Hotel>(model);
            var location = new Location()
            {
                Country = model.Country,
                City = model.City,
                Address = model.Address
            };
            hotel.Location = location;
            this.hotels.CreateHotel(hotel);

            this.TempData["Success"] = "Hotel was successful added!";
            return this.RedirectToAction("Index");
        }
Exemplo n.º 11
0
        public ActionResult Create(HotelInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            var hotel    = this.Mapper.Map <Hotel>(model);
            var location = new Location()
            {
                Country = model.Country,
                City    = model.City,
                Address = model.Address
            };

            hotel.Location = location;
            this.hotels.CreateHotel(hotel);

            this.TempData["Success"] = "Hotel was successful added!";
            return(this.RedirectToAction("Index"));
        }