// GET: Medewerkers/Delete/5 public async Task <IActionResult> Delete(int?id) { MedewerkerDTO medewerkerDTO = null; if (id.HasValue) { medewerkerDTO = await _medewerkerRepository.GetByIdAsync(id.Value); } else { return(NotFound()); } return(View(medewerkerDTO)); }
public async Task <ContractDTO> GetByIdAsync(int id) { Contract contract = await _context.Contracten .Include(c => c.Medewerker) .Where(r => r.ContractID == id) .SingleOrDefaultAsync(); ContractDTO contractDTO = new ContractDTO(contract); if (contract.Medewerker != null) { MedewerkerDTO medewerkerDTO = new MedewerkerDTO(contract.Medewerker); contractDTO.Medewerker = medewerkerDTO; } return(contractDTO); }
// GET: Medewerkers/Details/5 public async Task <IActionResult> Details(int?id) { MedewerkerDTO medewerkerDTO = null; if (id.HasValue) { medewerkerDTO = await _medewerkerRepository.GetByIdAsync(id.Value); } else { return(NotFound()); } medewerkerDTO.LeeftijdInJaren = _calculationsService.BerekenLeeftijdInJaren(medewerkerDTO.Geboortedatum); return(View(medewerkerDTO)); }
public async Task Detail_ReturnsAViewResult_WithAContractDTO() { //Arrange var contractID = 1; ContractDTO contract = (GetContracts().FirstOrDefault(m => m.ContractID == contractID)); var medewerkers = GetMedewerkers(); var medewerkerDTO = new MedewerkerDTO(medewerkers[1]); contract.medewerker = medewerkerDTO; _contractRepository.Setup(repo => repo.GetByIdAsync(contractID)).Returns(Task.FromResult(contract)); var controller = new ContractenController(_calculationsService, _unitOfWork.Object, _contractRepository.Object); //Act var result = await controller.Details(contractID); //Assert var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsType <ContractDTO>( viewResult.ViewData.Model); Assert.Equal(1, model.ContractID); }