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)); }
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()); } }
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)); }