コード例 #1
0
        public async Task <IActionResult> Update([FromBody] AccommodationViewModel viewModel)
        {
            var model        = Mapper.Map <Accommodation>(viewModel);
            var updatedModel = await _accommodationService.UpdateAsync(model);

            var updatedViewModel = Mapper.Map <AccommodationViewModel>(updatedModel);

            return(Ok(updatedViewModel));
        }
コード例 #2
0
        public async Task <IActionResult> Update(Guid id, [FromBody] AccommodationData accommodationData)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var accommodation = await service.UpdateAsync(id, mapper.MapFrom(accommodationData));

                    return(Ok(mapper.MapFrom(accommodation)));
                }

                return(BadRequest());
            }
            catch (FacilityNotFoundException)
            {
                return(NotFound());
            }
            catch (AccommodationNotFoundException)
            {
                return(NotFound());
            }
        }
コード例 #3
0
        public async Task <IActionResult> Edit(AccommodationViewModel accommodationViewModel)
        {
            if (ModelState.IsValid)
            {
                var details = mapper.MapFrom(accommodationViewModel);
                try
                {
                    await service.UpdateAsync(accommodationViewModel.Id, details);

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

            return(View(accommodationViewModel));
        }