コード例 #1
0
        public async Task <IActionResult> Edit(int id)
        {
            ViewData["Title"] = applicationPersister.GetTitoloApp();
            SocioFamiliareEditInputModel inputModel = await socifamiliari.GetSocioFamiliareForEditingAsync(id);

            return(View(inputModel));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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());
        }