Ejemplo n.º 1
0
 public IActionResult Cadastrar(Imovel imovel)
 {
     _context.Add(imovel);
     _context.SaveChanges();
     TempData["msg"] = "Imovel Registrado!";
     return(RedirectToAction("Cadastrar"));
 }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("ProdutoID,Nome,Preco")] Produto produto)
        {
            if (ModelState.IsValid)
            {
                _context.Add(produto);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(produto));
        }
        public async Task <IActionResult> Create([Bind("Nome,Data_de_Nascimento,Sexo,Id")] Aluno aluno)
        {
            if (ModelState.IsValid)
            {
                _context.Add(aluno);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(aluno));
        }
        public async Task <IActionResult> Create([Bind("Id,Codigo,Descricao")] Bandeira bandeira)
        {
            if (ModelState.IsValid)
            {
                _context.Add(bandeira);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(bandeira));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("Id,Description,Quantity,Points,Period,SelectedVerificationType")] CreateActivityRequests createActivityRequests)
        {
            if (ModelState.IsValid)
            {
                createActivityRequests.Id = Guid.NewGuid();
                _context.Add(createActivityRequests);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(createActivityRequests));
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            using (var context = new BancoContext())
            {
                context.Database.EnsureCreated();
            }

            Console.WriteLine("Database!");

            Console.ReadKey();

            using (var context = new BancoContext())
            {
                var author = new Author
                {
                    FirstName = "William",
                    LastName  = "Shakespeare",
                    Books     = new List <Book>
                    {
                        new Book {
                            Title = "Hamlet"
                        },
                        new Book {
                            Title = "Othello"
                        },
                        new Book {
                            Title = "MacBeth"
                        }
                    }
                };
                context.Add(author);
                context.SaveChanges();
            }

            Console.WriteLine("Save!");

            Console.ReadKey();

            using (var context = new BancoContext())
            {
                foreach (var book in context.Books)
                {
                    Console.WriteLine(book.Title);
                }
            }

            Console.WriteLine("Lista!");

            Console.WriteLine("Hello World!");

            Console.ReadKey();
        }
        public async Task <IActionResult> Create([Bind("ID,AdquirenteId,CodigoCliente,DataTransacao,HoraTransacao,NumeroCartao,CodigoAutorizacao,NSU,BandeiraId,ValorBruto,TaxaAdmin,ValorLiquido")] Transacoes transacoes)
        {
            if (ModelState.IsValid)
            {
                _context.Add(transacoes);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AdquirenteId"] = new SelectList(_context.Set <Adquirente>(), "Id", "Id", transacoes.AdquirenteId);
            ViewData["BandeiraId"]   = new SelectList(_context.Set <Bandeira>(), "Id", "Id", transacoes.BandeiraId);
            return(View(transacoes));
        }
        public PadraoResult <Materia> CadastrarMateria(Materia materia)
        {
            var validator = new MateriaValidator();
            var valida    = validator.Valida(materia);
            var result    = new PadraoResult <Materia>();

            if (!valida.IsValid)
            {
                result.Error   = true;
                result.Message = valida.Erros;
                result.Status  = HttpStatusCode.BadRequest;
                return(result);
            }

            try
            {
                using (db)
                {
                    foreach (var item in db.Materias)
                    {
                        if (item.Nome == materia.Nome)
                        {
                            result.Error = true;
                            result.Message.Add($"O nome {materia.Nome} já esta cadastrado");
                            result.Status = HttpStatusCode.BadRequest;
                            return(result);
                        }
                    }
                    db.Add(materia);
                    db.SaveChanges();
                    result.Error  = false;
                    result.Status = HttpStatusCode.OK;
                    result.Data   = db.Materias.ToList();
                    return(result);
                }
            }
            catch (Exception e)
            {
                result.Error = true;
                result.Message.Add(e.Message);
                result.Status = HttpStatusCode.BadRequest;
                return(result);
            }
        }
 public bool Adicionar(Usuario usuario)
 {
     _context.Add(usuario);
     _context.SaveChanges();
     return(true);
 }