public async Task <IActionResult> Create([Bind("TarefaId,Nome,Descricao,Inicio,Fim,Importancia,Foto")] Tarefa tarefa, IFormFile foto)
        {
            if (ModelState.IsValid)
            {
                if (foto != null)
                {
                    byte[] b;
                    using (var or = foto.OpenReadStream())
                    {
                        using (var ms = new MemoryStream())
                        {
                            or.CopyTo(ms);
                            b = ms.ToArray();
                        }
                    }
                    tarefa.Foto = b;
                }

                _context.Add(tarefa);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tarefa));
        }
Esempio n. 2
0
        public static void InserirTarefa(TarefaContext db)
        {
            string descricao = "";

            Console.WriteLine("\nInserindo uma nova tarefa: ");
            descricao = Console.ReadLine();
            db.Add(new Tarefa {
                Descricao = descricao, Realizado = false
            });
            db.SaveChanges();
        }
Esempio n. 3
0
 public void Add <T>(T entity) where T : class
 {
     _context.Add(entity);
 }