public Lodging Create(Lodging lodging, Guid touristSpotId, List <string> pathOfPictures)
        {
            try
            {
                VerifyIfLodgingExist(lodging, touristSpotId);
                lodging.Id = Guid.NewGuid();
                TouristSpot touristSpotForLodging = touristSpotManagementLogic.GetTouristSpotById(touristSpotId);
                lodging.TouristSpot = touristSpotForLodging;

                if (pathOfPictures != null)
                {
                    foreach (string picturePath in pathOfPictures)
                    {
                        Picture pictureOfLodging = new Picture()
                        {
                            Path = picturePath,
                            Id   = Guid.NewGuid()
                        };

                        LodgingPicture lodgingPicture = new LodgingPicture()
                        {
                            Lodging   = lodging,
                            LodgingId = lodging.Id,
                            Picture   = pictureOfLodging,
                            PictureId = pictureOfLodging.Id
                        };
                        lodging.Images.Add(lodgingPicture);
                    }
                }
                lodging.VerifyFormat();
                lodgingRepository.Add(lodging);
                return(lodging);
            }
            catch (LodgingException e)
            {
                throw new DomainBusinessLogicException(e.Message);
            }
            catch (DomainBusinessLogicException e)
            {
                throw new DomainBusinessLogicException(e.Message);
            }
            catch (ClientBusinessLogicException e)
            {
                throw new ClientBusinessLogicException(MessageExceptionBusinessLogic.ErrorCreatingLodging, e);
            }
            catch (ServerException e)
            {
                throw new ServerBusinessLogicException("No se puede crear el hospedaje debido a que ha ocurrido un error.", e);
            }
        }
 public IActionResult Get(Guid id)
 {
     try
     {
         TouristSpot touristSpot = touristSpotManagement.GetTouristSpotById(id);
         return(Ok(TouristSpotForResponseModel.ToModel(touristSpot)));
     }
     catch (ClientBusinessLogicException e)
     {
         return(NotFound(e.Message));
     }
     catch (ServerBusinessLogicException e)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
     }
 }
Exemple #3
0
        public Lodging Create(Lodging lodging, TouristSpot touristSpot, List <string> pathOfPictures)
        {
            try
            {
                Lodging lodgingObteined = lodgingRepository.GetLodgingByNameAndTouristSpot(lodging.Name, touristSpot.Id);
                if (lodgingObteined != null)
                {
                    throw new DomainBusinessLogicException(MessageExceptionBusinessLogic.ErrorLodgingAlredyExist);
                }
                lodging.Id = Guid.NewGuid();
                TouristSpot touristSpotForLodging;
                try
                {
                    touristSpotForLodging = touristSpotManagementLogic.GetTouristSpotById(touristSpot.Id);
                }
                catch (ClientBusinessLogicException)
                {
                    touristSpotForLodging = touristSpotManagementLogic.Create(touristSpot, touristSpot.Region.Id, touristSpot.ListOfCategories.ConvertAll(c => c.CategoryId));
                }

                lodging.TouristSpot = touristSpotForLodging;

                if (pathOfPictures != null)
                {
                    foreach (string picturePath in pathOfPictures)
                    {
                        Picture pictureOfLodging = new Picture()
                        {
                            Path = picturePath,
                            Id   = Guid.NewGuid()
                        };

                        LodgingPicture lodgingPicture = new LodgingPicture()
                        {
                            Lodging   = lodging,
                            LodgingId = lodging.Id,
                            Picture   = pictureOfLodging,
                            PictureId = pictureOfLodging.Id
                        };
                        lodging.Images.Add(lodgingPicture);
                    }
                }
                lodging.VerifyFormat();
                lodgingRepository.Add(lodging);
                return(lodging);
            }
            catch (LodgingException e)
            {
                throw new DomainBusinessLogicException(e.Message);
            }
            catch (DomainBusinessLogicException e)
            {
                throw new DomainBusinessLogicException(e.Message);
            }
            catch (ClientBusinessLogicException e)
            {
                throw new ClientBusinessLogicException(MessageExceptionBusinessLogic.ErrorCreatingLodging, e);
            }
            catch (ServerException e)
            {
                throw new ServerBusinessLogicException("No se puede crear el hospedaje debido a que ha ocurrido un error.", e);
            }
        }