//[HttpGet] per identificare in modo esplicito che il Create() e di visualizzazione della view public IActionResult Create() { ViewData["Descrizione"] = "Nuova Password"; var var_InputModel = new PasswordCreateInputModel(); return(View(var_InputModel)); }
public async Task <PasswordDetailViewModel> CreatePasswordAsync(PasswordCreateInputModel par_InputModel) { string sDescrizione = par_InputModel.Descrizione; string sDataInserimento = Convert.ToString(DateTime.Now); string sFkUtente; try { sFkUtente = par_HttpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; } catch (NullReferenceException) { throw new Exception("E' necessario un utente per effettuare questa operazione."); } bool bPasswordNonDuplicata = await DescrizioneDuplicataAsync(sDescrizione, 0); if (bPasswordNonDuplicata == true) { var var_Password = new Passwords(); var_Password.Descrizione = sDescrizione; var_Password.DataInserimento = sDataInserimento; var_Password.FkUtente = sFkUtente; dbContext.Add(var_Password); await dbContext.SaveChangesAsync(); PasswordDetailViewModel var_DetailPassword = PasswordDetailViewModel.FromEntity(var_Password); return(var_DetailPassword); } else { throw new PasswordDescrizioneDuplicataException(sDescrizione, new Exception("errore nella creazione della password")); } }
[HttpPost] //per identificare in modo esplicito che il Create(PasswordCreateInputModel Par_InputModel) e di reperimento info da bottone post nella view public async Task <IActionResult> Create(PasswordCreateInputModel par_InputModel) { if (ModelState.IsValid == true) { try { PasswordDetailViewModel var_Password = await prop_PasswordService.CreatePasswordAsync(par_InputModel); TempData["MessaggioConfermaSalvataggio"] = "Il record e stato creato, per inserire la password usare la funzione di modifica"; return(RedirectToAction(nameof(Edit), new { Id = var_Password.Id })); } catch (PasswordDescrizioneDuplicataException) { ModelState.AddModelError(nameof(PasswordDetailViewModel.Descrizione), "Questa Password gia esiste"); } } ViewData["Descrizione"] = "Nuova Password"; return(View(par_InputModel)); }
public async Task <PasswordDetailViewModel> CreatePasswordAsync(PasswordCreateInputModel par_InputModel) { string sDescrizione = par_InputModel.Descrizione; string sDataInserimento = Convert.ToString(DateTime.Now); bool bPasswordNonDuplicata = await DescrizioneDuplicataAsync(sDescrizione, 0); if (bPasswordNonDuplicata == true) { PasswordDetailViewModel var_Password; string sId = await db.QueryScalarAsync <string>($@"INSERT INTO Passwords (Descrizione, DataInserimento) VALUES ({sDescrizione}, {sDataInserimento}); SELECT last_insert_rowid();"); var_Password = await GetPasswordAsync(sId); return(var_Password); } else { throw new PasswordDescrizioneDuplicataException(sDescrizione, new Exception("errore nella creazione della password")); } }
public Task<PasswordDetailViewModel> CreatePasswordAsync(PasswordCreateInputModel par_InputModel) { return prop_PasswordService.CreatePasswordAsync(par_InputModel); }