public async Task <IActionResult> Edit(Guid id, [Bind("TipoAtivoId,Nome")] TipoAtivo tipoAtivo) { if (id != tipoAtivo.TipoAtivoId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(tipoAtivo); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TipoAtivoExists(tipoAtivo.TipoAtivoId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(tipoAtivo)); }
public async Task <IActionResult> Create([Bind("TipoAtivoId,Nome")] TipoAtivo tipoAtivo) { if (ModelState.IsValid) { tipoAtivo.TipoAtivoId = Guid.NewGuid(); _context.Add(tipoAtivo); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(tipoAtivo)); }
internal Boolean Gravar(TipoAtivo tipoAtivo) { b.getComandoSQL().Parameters.Clear(); if (tipoAtivo.GetCodigo() == 0) { b.getComandoSQL().CommandText = @"insert into Tipo_Ativo (tpa_descricao,tpa_valor, tpa_stativo) values(@descricao,@valor, @ativo);"; } else { b.getComandoSQL().CommandText = @"update Tipo_Ativo set tpa_descricao = @descricao, tpa_valor = @valor, tpa_stativo = @ativo where tpa_codigo = @codigo;"; b.getComandoSQL().Parameters.AddWithValue("@codigo", tipoAtivo.GetCodigo()); } b.getComandoSQL().Parameters.AddWithValue("@descricao", tipoAtivo.GetDescricao()); b.getComandoSQL().Parameters.AddWithValue("@ativo", tipoAtivo.GetStAtivo()); b.getComandoSQL().Parameters.AddWithValue("@valor", tipoAtivo.GetValor()); return(b.ExecutaComando() == 1); }
public static IReadOnlyDictionary <string, Ativo> GetOrCreate(Func <IEnumerable <string> > factory, TipoAtivo tipo) { var dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var path = Path.Combine(dir, $"{tipo}.json"); IEnumerable <string> ativos; if (File.Exists(path)) { using var streamFile = new StreamReader(path); var content = streamFile.ReadToEnd(); ativos = JsonSerializer.Deserialize <string[]>(content); } else { ativos = factory(); var content = JsonSerializer.Serialize(ativos); File.WriteAllText(path, content); } return(ativos .Select(x => new Ativo { Ticker = x, Tipo = tipo }) .ToDictionary(x => x.Ticker)); }