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);
            }
        }
Exemplo n.º 2
0
        public Lodging Create(Lodging lodging)
        {
            var touristSpot = TouristSpotRepository.Get(lodging.TouristSpot.Id);

            if (touristSpot == null)
            {
                throw new NotFoundException("TouristSpot");
            }

            if (LodgingRepository.Exists(x => x.Address == lodging.Address && x.IsDeleted == false))
            {
                throw new NotUniqueException("Address");
            }

            lodging.TouristSpot = touristSpot;
            LodgingRepository.Add(lodging);
            LodgingRepository.Save();

            return(LodgingRepository.GetFirst(x => x.Id == lodging.Id, "TouristSpot,Images"));
        }
Exemplo n.º 3
0
 public void Add(Lodging lodging)
 {
     // Add specific business logic here
     _lodgingRepository.Add(lodging);
 }
Exemplo n.º 4
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);
            }
        }