//construtor com argumento public Client(int id, string nome, string email, DateTime?birthDate, TipoRegistroNacional tipoRegistroNacional, int registroNacional) //Tipo tipo// { Id = id; Nome = nome; Email = email; BirthDate = birthDate; TipoRegistroNacional = tipoRegistroNacional; RegistroNacional = registroNacional; //Tipo = tipo; }
/* * public async Task<IActionResult> Create([Bind("Id,Nome")] TipoRegistroNacional tipoRegistroNacional) */ public async Task <IActionResult> Create([Bind("Id,Nome")] TipoRegistroNacional tipoRegistroNacional) { if (ModelState.IsValid) { /* * _context.Add(tipoRegistroNacional); * await _context.SaveChangesAsync(); */ await _tipoRegistroNacionalService.InsertAsync(tipoRegistroNacional); return(RedirectToAction(nameof(Index))); } return(View(tipoRegistroNacional)); }
/* * public async Task<IActionResult> Edit(int id, [Bind("Id,Nome")] TipoRegistroNacional tipoRegistroNacional) */ public async Task <IActionResult> Edit(int id, TipoRegistroNacional tipoRegistroNacional) { if (id != tipoRegistroNacional.Id) { /* * return NotFound(); */ return(RedirectToAction(nameof(Error), new { message = "Id mismatch" })); } if (ModelState.IsValid) { try { /* * _context.Update(tipoRegistroNacional); * await _context.SaveChangesAsync(); */ await _tipoRegistroNacionalService.UpdateAsync(tipoRegistroNacional); } /* * catch (DbUpdateConcurrencyException) */ catch (DbUpdateConcurrencyException e) { /* * if (!TipoRegistroNacionalExists(tipoRegistroNacional.Id)) */ if (tipoRegistroNacional == null) { /* * return NotFound(); */ return(RedirectToAction(nameof(Error), new { message = "Id not found" })); } else { /* * throw; */ return(RedirectToAction(nameof(Error), new { message = e.Message })); } } return(RedirectToAction(nameof(Index))); } return(View(tipoRegistroNacional)); }
/* * public async Task<IActionResult> Create([Bind("Id,Nome,Email,Aniversario,SalarioBase")] Operador operador) */ public async Task InsertAsync([Bind("Id,Nome")] TipoRegistroNacional tipoRegistroNacional) { /* * if (ModelState.IsValid) * { * } */ /* * _context.Add(tipoRegistroNacional); */ _context.TipoRegistroNacional.Add(tipoRegistroNacional); await _context.SaveChangesAsync(); /* * return RedirectToAction(nameof(Index)); * * return View(operador); */ }
/* * public async Task<IActionResult> Edit(int id, [Bind("Id,Nome,Email,Aniversario,SalarioBase")] Operador operador) */ public async Task UpdateAsync(TipoRegistroNacional tipoRegistroNacional) { /* * if (id != operador.Id) */ if (!await _context.TipoRegistroNacional.AnyAsync(x => x.Id == tipoRegistroNacional.Id)) { throw new NotFoundException("Id not found"); } /* * if (ModelState.IsValid) * { */ try { _context.Update(tipoRegistroNacional); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException e) { if (!TipoRegistroNacionalExists(tipoRegistroNacional.Id)) { throw new NotFoundException("Id not found"); } else { throw new DbConcurrencyException(e.Message); } } /* * return RedirectToAction(nameof(Index)); * * } * * return View(operador); */ }