Exemplo n.º 1
0
        public IActionResult Post([FromForm] LodgingModel lodgingModel)
        {
            IActionResult result;

            if (lodgingModel.HasErrors())
            {
                result = BadRequest(new ErrorModel(lodgingModel.Errors()));
            }
            else
            {
                var lodging = LodgingLogic.Create(lodgingModel.ToEntity());
                result = Created("GetAdministrator", new LodgingBasicInfoModel(lodging));
            }

            return(result);
        }
        private void CreateFromParsedModel(LodgingParsed lodgingParsed)
        {
            var lodging = new Lodging
            {
                Name                = lodgingParsed.Name,
                Description         = lodgingParsed.Description,
                Address             = lodgingParsed.Address,
                Rating              = lodgingParsed.Rating,
                PricePerNight       = lodgingParsed.PricePerNight,
                ConfirmationMessage = lodgingParsed.ConfirmationMessage,
                Phone               = lodgingParsed.Phone,
                TouristSpot         = TouristSpotFromParsedModel(lodgingParsed)
            };

            if (!lodging.IsValid("Images"))
            {
                throw new EntityNotValidException(lodging.Validate("Images"));
            }

            LodgingLogic.Create(lodging);
        }