public async Task <Sons> ToSonsAsync(SonsViewModel model, bool isNew) { return(new Sons { Id = isNew ? 0 : model.Id, Name = model.Name, Datebirth = model.Datebirth, Genero = model.Genero, Employee = await _dataContext.Employees.FindAsync(model.EmployeeId) }); }
public async Task <IActionResult> AddSons(SonsViewModel model) { if (ModelState.IsValid) { var sons = await _converterHelper.ToSonsAsync(model, true); _dataContext.Sons.Add(sons); await _dataContext.SaveChangesAsync(); return(RedirectToAction($"Details/{model.EmployeeId}")); } return(View(model)); }
public async Task <IActionResult> AddSons(int?id) { if (id == null) { return(NotFound()); } var employe = await _dataContext.Employees.FindAsync(id); if (employe == null) { return(NotFound()); } var model = new SonsViewModel { EmployeeId = employe.Id, }; return(View(model)); }