public async Task <IActionResult> Create([Bind("Amount,EmployeeId,UnitPrice,ProjectId")] ProjectDrivingViewModel projectDrivingViewModel) { if (ModelState.IsValid) { //_context.Add(projectDrivingViewModel); //await _context.SaveChangesAsync(); await _employeeService.AddAsync(ProjectDrivingMapper.Map(projectDrivingViewModel)); return(RedirectToAction("details", "project", new { id = projectDrivingViewModel.ProjectId })); } //ViewData["EmployeeId"] = new SelectList(_context.Employees, "Id", "Id", projectDrivingViewModel.EmployeeId); return(RedirectToAction("details", "project", new { id = projectDrivingViewModel.ProjectId })); }
//----------------------------- public async Task <IActionResult> Create([Bind("Id,Name,Phone,Salary,Active")] EmployeeViewModel employeeViewModel) { try { if (ModelState.IsValid) { await _employeeService.AddAsync(EmployeeMapper.Map(employeeViewModel)).ConfigureAwait(false); return(RedirectToAction(nameof(Index))); //_context.Add(employeeViewModel); //await _context.SaveChangesAsync(); //return RedirectToAction(nameof(Index)); } return(View(employeeViewModel)); } catch (Exception) { ErrorViewModel model = new ErrorViewModel { RequestId = "Medarbejderen kunne ikke oprettes" }; return(View("Error", model)); } }