public async Task <IActionResult> Edit(int?id) { if (id == null || id <= 0) { _logger.LogWarn($"Invalid value passed to method {nameof(Edit)} in AppointmentController"); return(RedirectToAction(nameof(Index))); } EditAppointmentManagementDTO appointment = _mapper.Map <EditAppointmentManagementDTO>(await _repositoryWrapper.Appointment.GetAppointmentByIdAsync(id)); List <Listing> x = await _repositoryWrapper.Listing.GetAllListingsAsync(); List <SelectListItem> list = new List <SelectListItem>(); foreach (var item in x) { if (id == item.Id) { list.Add(new SelectListItem($"{item}", $"{item.Id}", true)); } else { list.Add(new SelectListItem($"{item}", $"{item.Id}")); } } ViewBag.listing = list; return(View(nameof(Edit), appointment)); }
public async Task <IActionResult> Edit(int id, EditAppointmentManagementDTO appointment) { if (id != appointment.Id) { _logger.LogWarn($" Id: {id} does not match appointmentId value "); return(RedirectToAction(nameof(Index))); } if (ModelState.IsValid) { try { Appointment app = _mapper.Map <Appointment>(appointment); _repositoryWrapper.Appointment.UpdateAppointment(app); await _repositoryWrapper.SaveAsync(); } catch (Exception ex) { _logger.LogError($"error occurred when updating {appointment.Id}. {ex}"); } return(RedirectToAction(nameof(Index))); } return(View(nameof(Edit), appointment)); }
public EditShould() { fixture = new SetupFixture(); sut = new AppointmentController(fixture.Logger.Object, fixture.repositoryWrapper.Object, fixture.mapper.Object ); fixture.repositoryWrapper .Setup(x => x.Appointment.GetAppointmentByIdAsync(It.IsAny <int>())) .ReturnsAsync(new Appointment()); fixture.repositoryWrapper .Setup(x => x.Listing.GetAllListingsAsync()) .ReturnsAsync(new List <Listing>()); fixture.repositoryWrapper .Setup(x => x.Listing.GetAllListingsAsync()) .ReturnsAsync(new List <Listing>()); fixture.mapper.Setup(x => x.Map <EditAppointmentManagementDTO>(It.IsAny <Appointment>())) .Returns(new EditAppointmentManagementDTO()); app = new EditAppointmentManagementDTO() { Id = 1 }; }