public async Task <IActionResult> PutAutor([FromRoute] int id, [FromBody] Autor autor)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != autor.AutorId)
            {
                return(BadRequest());
            }

            _context.Entry(autor).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AutorExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 2
0
 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);
 }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 6
0
        public async Task <ActionResult> Create([Bind(Include = "Id,Name")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
Ejemplo n.º 7
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));
        }
Ejemplo n.º 8
0
        // GET: Questions/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Question question = await db.Questions.FindAsync(id);

            if (question == null)
            {
                return(HttpNotFound());
            }
            question.ViewCount += 1;
            await db.SaveChangesAsync();

            return(View(question));
        }
Ejemplo n.º 9
0
        public async Task <ActionResult> Add(AddAnswerViewModel answer)
        {
            if (ModelState.IsValid)
            {
                Question question = await db.Questions.SingleAsync(x => x.Id == answer.QuestionId);

                question.Answers.Add(new Answer(answer.Text));
                await db.SaveChangesAsync();

                return(RedirectToAction("Details", "Questions", new { id = answer.QuestionId }));
            }

            return(View(answer));
        }
        public async Task <IActionResult> CreateQuestionAsync([FromBody] AskQuestion quest)
        {
            try
            {
                Question question = new Question();
                question.Question1   = quest.question;
                question.AskedBy     = quest.askedBy;
                question.AskedByName = quest.askedByName;

                db.Question.Add(question);
                await db.SaveChangesAsync();

                return(Ok("Success"));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public async Task <IActionResult> CreateAnswerAsync([FromBody] AnswerQuestion ans)
        {
            try
            {
                Answer answer = new Answer();
                answer.QuestionId     = ans.question_id;
                answer.Answer1        = ans.answer;
                answer.AnsweredBy     = ans.answeredBy;
                answer.AnsweredByName = ans.answeredByName;

                db.Answer.Add(answer);
                await db.SaveChangesAsync();

                return(Ok("Success"));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }