public async Task <IActionResult> Edit(int id, [Bind("ID,UserID,AnswerID")] PositiveVote positiveVote) { if (id != positiveVote.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(positiveVote); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PositiveVoteExists(positiveVote.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["AnswerID"] = new SelectList(_context.Answer, "Id", "Description", positiveVote.AnswerID); ViewData["UserID"] = new SelectList(_context.User, "ID", "ID", positiveVote.UserID); return(View(positiveVote)); }
// POST: PositiveV/Create // To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see http://go.microsoft.com/fwlink/?LinkId=317598. public async Task <int> Create([Bind("ID,UserID,AnswerID")] PositiveVote positiveVote) { if (ModelState.IsValid) { var lista = _context.PositiveVote.Where(x => x.UserID == positiveVote.UserID && x.AnswerID == positiveVote.AnswerID).ToList(); if (lista.Count() > 0) { _context.PositiveVote.Remove(lista.First()); await _context.SaveChangesAsync(); return(-1); } else { _context.Add(positiveVote); await _context.SaveChangesAsync(); return(1); } } return(0); }
public async Task <IActionResult> PostPositiveVote([FromBody] PositiveVotePostResourceModel positiveVote) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var positiveVoteToInsert = new PositiveVote() { VoterId = positiveVote.VoterId, IdeaId = positiveVote.IdeaId }; await unitOfWork.PositiveVoteRepository.InsertAsync(positiveVoteToInsert); unitOfWork.Complete(); //return CreatedAtAction("GetPositiveVote", new { id = positiveVoteToInsert.Id }, positiveVoteToInsert); return(Ok(positiveVoteToInsert)); }