Пример #1
0
        public T Add(T itemToAdd)
        {
            var entity = dbContext.Add <T>(itemToAdd);

            dbContext.SaveChanges();
            return(entity.Entity);
        }
 public async Task<IActionResult> Create([Bind("UserId,EmailAdress,Password,DateOfBirth,FirstName,LastName,University,GithubRating,CodeforcesRating,PhoneNumber,Adress,PointsAccumulated")] User user)
 {
     if (ModelState.IsValid)
     {
         _context.Add(user);
         await _context.SaveChangesAsync();
         return RedirectToAction(nameof(Index));
     }
     return View(user);
 }
Пример #3
0
        public async Task <IActionResult> Create([Bind("AutorId,Nome,Login,Senha")] Autor autor)
        {
            if (ModelState.IsValid)
            {
                _context.Add(autor);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(autor));
        }
Пример #4
0
        public async Task <IActionResult> Create([Bind("TagId,Nome")] Tag tag)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tag);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tag));
        }
Пример #5
0
        public async Task <IActionResult> Create([Bind("CategoriaId,Titulo,Descricao")] Categoria categoria)
        {
            if (ModelState.IsValid)
            {
                _context.Add(categoria);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(categoria));
        }
Пример #6
0
        public async Task <IActionResult> Create([Bind("PerguntaId,Titulo,Descricao,DataPublicacao,AutorId,CategoriaId")] Pergunta pergunta)
        {
            if (ModelState.IsValid)
            {
                _context.Add(pergunta);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AutorId"]     = new SelectList(_context.Autores, "AutorId", "Login", pergunta.AutorId);
            ViewData["CategoriaId"] = new SelectList(_context.Categorias, "CategoriaId", "Descricao", pergunta.CategoriaId);
            return(View(pergunta));
        }