public async Task <IActionResult> PutPollUser([FromRoute] long id, [FromBody] PollUser pollUser) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != pollUser.PollUserID) { return(BadRequest()); } _context.Entry(pollUser).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PollUserExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutPoll([FromRoute] long id, [FromBody] Poll poll) { var userID = User.Claims.FirstOrDefault(c => c.Type == "UserID").Value; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != poll.PollID) { return(BadRequest()); } var pollUser = await _context.PollUser.Where(p => p.PollID == id).Where(p => p.UserID == long.Parse(userID)).SingleOrDefaultAsync(); pollUser.gestemd = true; _context.Entry(pollUser).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PollExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> UpdateVriend([FromRoute] long vriendID, [FromBody] Vriend vriend) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (vriendID != vriend.VriendID) { return(BadRequest()); } var user = await _context.Users.Where(u => u.UserName == vriend.UserName).SingleOrDefaultAsync(); var userName = User.Claims.FirstOrDefault(c => c.Type == "UserName").Value; var userID = User.Claims.FirstOrDefault(c => c.Type == "UserID").Value; var ikZelf = await _context.Vriend.Where(v => v.UserName == userName).SingleOrDefaultAsync(); var vriendUser = await _context.VriendUser.Where(v => v.UserID == user.UserID).Where(s => s.VriendID == ikZelf.VriendID).SingleOrDefaultAsync(); vriendUser.Status = true; var vriendUser2 = new VriendUser(); vriendUser2.VriendID = vriend.VriendID; vriendUser2.UserID = long.Parse(userID); vriendUser2.Status = true; _context.VriendUser.Add(vriendUser2); await _context.SaveChangesAsync(); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!VriendExists(vriendID)) { return(NotFound()); } else { throw; } } return(NoContent()); }