public IActionResult Post([FromBody] TouristSpotForRequestModel aTouristSpot) { try { TouristSpot touristSpotAdded = touristSpotManagement.Create(TouristSpotForRequestModel.ToEntity(aTouristSpot), aTouristSpot.RegionId, aTouristSpot.ListOfCategoriesId); return(CreatedAtRoute("touristSpot", new { id = touristSpotAdded.Id }, TouristSpotForResponseModel.ToModel(touristSpotAdded))); } catch (DomainBusinessLogicException e) { return(BadRequest(e.Message)); } catch (ClientBusinessLogicException e) { return(NotFound(e.Message)); } catch (ServerBusinessLogicException e) { return(StatusCode(StatusCodes.Status500InternalServerError, e.Message)); } }
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); } }