public async Task <IActionResult> Create([FromRoute] Guid facilityId, [FromBody] AccommodationData accommodationData)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var accommodation = await service.CreateAsync(facilityId, mapper.MapFrom(accommodationData));

                    return(CreatedAtAction("Find", new { id = accommodation.Id }, mapper.MapFrom(accommodation)));
                }

                return(BadRequest());
            }
            catch (FacilityNotFoundException)
            {
                return(NotFound());
            }
        }
Exemple #2
0
        public async Task <IActionResult> Create(Guid?id, AccommodationViewModel accommodationViewModel)
        {
            if (ModelState.IsValid)
            {
                var details = mapper.MapFrom(accommodationViewModel);
                try
                {
                    await service.CreateAsync(accommodationViewModel.FacilityId, details);

                    return(RedirectToAction("details", "facility", new { id = accommodationViewModel.FacilityId }));
                }
                catch (FacilityNotFoundException)
                {
                    return(View("NotFound"));
                }
            }

            ViewBag.FacilityId = accommodationViewModel.FacilityId;
            return(View(accommodationViewModel));
        }