public async Task <IActionResult> Edit(int id) { ViewData["Title"] = applicationPersister.GetTitoloApp(); SocioFamiliareEditInputModel inputModel = await socifamiliari.GetSocioFamiliareForEditingAsync(id); return(View(inputModel)); }
public async Task <IActionResult> Edit(SocioFamiliareEditInputModel inputModel) { if (ModelState.IsValid) { SocioFamiliareDetailViewModel socio = await socifamiliari.EditSocioFamiliareAsync(inputModel); TempData["ConfirmationMessage"] = "I dati sono stati aggiornati con successo"; return(RedirectToAction(nameof(SociController.Detail), "Soci", new { id = inputModel.SocioId })); } ViewData["Title"] = applicationPersister.GetTitoloApp(); return(View(inputModel)); }
public async Task <SocioFamiliareEditInputModel> GetSocioFamiliareForEditingAsync(int id) { IQueryable <SocioFamiliareEditInputModel> queryLinq = dbContext.SociFamiliari .AsNoTracking() .Where(socioFamiliare => socioFamiliare.Id == id) .Select(socioFamiliare => socioFamiliare.ToSocioFamiliareEditInputModel()); SocioFamiliareEditInputModel viewModel = await queryLinq.FirstOrDefaultAsync(); if (viewModel == null) { logger.LogWarning("Socio familiare {id} non trovato", id); throw new SocioFamiliareNotFoundException(id); } return(viewModel); }
public async Task <SocioFamiliareDetailViewModel> EditSocioFamiliareAsync(SocioFamiliareEditInputModel inputModel) { SocioFamiliare socioFamiliare = await dbContext.SociFamiliari.FindAsync(inputModel.Id); if (socioFamiliare == null) { logger.LogWarning("Socio familiare {id} non trovato", inputModel.Id); throw new SocioFamiliareNotFoundException(inputModel.Id); } socioFamiliare.ChangeSocioId(inputModel.SocioId); socioFamiliare.ChangeFamiliare(inputModel.Familiare); await dbContext.SaveChangesAsync(); return(socioFamiliare.ToSocioFamiliareDetailViewModel()); }