public void Add(Accommodation accommodation, string touristSpotName)
 {
     try
     {
         var touristSpot = accommodation.TouristSpot = touristSpotLogic.GetByName(touristSpotName);
         accommodation.TouristSpot = touristSpot;
         accommodationRepository.Add(accommodation);
     }
     catch (ObjectNotFoundInDatabaseException e)
     {
         throw new ObjectNotFoundInDatabaseException();
     }
     catch (RepeatedObjectException ex)
     {
         throw new RepeatedObjectException();
     }
     catch (Exception e)
     {
     }
 }
Esempio n. 2
0
        public IActionResult SaveNew(NewAccommodationVM model)
        {
            if (!ModelState.IsValid)
            {
                return(View("New"));
            }

            string uniqueFileName = Image.Upload(model.ProfileImage, _webHostEnvironment, "accommodations");

            Accommodation accommodation = new Accommodation()
            {
                Name        = model.Name,
                Distance    = model.Distance,
                PhoneNumber = model.PhoneNumber,
                Description = model.Description,
                Address     = model.Address,
                Picture     = uniqueFileName
            };

            _repo.Add(accommodation);
            return(RedirectToAction("List"));
        }