public async Task <IActionResult> ConfirmFriend(int id) { Vriend vriend = await _context.Vrienden.FindAsync(id); if (vriend.bevestigd == false) { vriend.bevestigd = true; } _context.Entry(vriend).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!VriendExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult <Friend> AcceptFriend(int userid, int friendid) { //get the Userfriend object from the users friendlist var userFriend = _context.Users.Include(u => u.Friends).SingleOrDefault(u => u.UserID == userid).Friends.SingleOrDefault(f => f.UserFriendID == friendid); if (userFriend != null) { //set the status to 3 (accepted) and set the object as modified. userFriend.Status = 3; _context.Entry(userFriend).State = EntityState.Modified; } else { return(BadRequest()); } //get the senders userfriend object from the friendlist. var userFriend2 = _context.Users.Include(u => u.Friends).SingleOrDefault(u => u.UserID == friendid).Friends.SingleOrDefault(f => f.UserFriendID == userid); if (userFriend2 != null) { //set the status to 3 (accepted) and set the object as modified. and save all changes userFriend2.Status = 3; _context.Entry(userFriend2).State = EntityState.Modified; _context.SaveChanges(); return(Ok()); } else { return(BadRequest()); } }
public async Task <IActionResult> PutVote(long id, Vote vote) { if (id != vote.VoteId) { return(BadRequest()); } _context.Entry(vote).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!VoteExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <Friend> > PutMakeFriends(Friend friend) { _context.Entry(friend).Property("Accepted").IsModified = true; await _context.SaveChangesAsync(); return(await _context.Friends.Include(r => r.Receiver).Include(s => s.Sender).FirstOrDefaultAsync(f => f.FriendID == friend.FriendID)); }
public async Task <IActionResult> PutAntwoord(int id, Antwoord antwoord) { if (id != antwoord.AntwoordID) { return(BadRequest()); } _context.Entry(antwoord).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AntwoordExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutStem(int id, Stem stem) { if (id != stem.StemID) { return(BadRequest()); } _context.Entry(stem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutFriendship(long id, Friendship friendship) { if (id != friendship.FriendshipId) { return(BadRequest()); } _context.Entry(friendship).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FriendshipExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutUser(int id, User user) { if (id != user.Id) { return(BadRequest()); } _context.Entry(user).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutEvaluation(int id, Evaluation evaluation) { if (id != evaluation.Id) { return(BadRequest()); } _context.Entry(evaluation).State = EntityState.Modified; try { await _context.SaveChangesAsync(); return(Ok(evaluation)); } catch (DbUpdateConcurrencyException) { if (!EvaluationExists(id)) { return(NotFound()); } else { throw; } } //return NoContent(); }
public async Task <IActionResult> PutVriendschap(int id, Vriendschap vriendschap) { if (id != vriendschap.VriendschapID) { return(BadRequest()); } _context.Entry(vriendschap).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!VriendschapExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task<IActionResult> PutParticipation(long id, Participation participation) { if (id != participation.ParticipationId) { return BadRequest(); } _context.Entry(participation).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ParticipationExists(id)) { return NotFound(); } else { throw; } } return NoContent(); }
public async Task <IActionResult> PutPoll(int id, Poll poll) { if (id != poll.PollID) { return(BadRequest()); } _context.Entry(poll).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PollExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <Relatie> > PutRelatie(int id, Relatie relatie) { if (id != relatie.RelatieID) { return(BadRequest()); } _context.Entry(relatie).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RelatieExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public virtual void Update(TEntity obj) { try { var local = _context.Set <TEntity>().Local.FirstOrDefault(); if (local != null) { _context.Entry(local).State = EntityState.Detached; } _context.Entry(obj).State = EntityState.Modified; _context.SaveChanges(); } catch (Exception ex) { throw ex; } }
public async Task <ActionResult <Stem> > GetCount(int pollId) { var opties = await _context.Opties .Where(p => p.PollID == pollId) .ToListAsync(); foreach (Optie optie in opties) { optie.Count = _context.Stemmen .Where(s => s.OptieID == optie.OptieID) .Count(); _context.Entry(optie).State = EntityState.Modified; await _context.SaveChangesAsync(); } return(Ok()); }
public async Task <IActionResult> PutPollUser(PollUser pollUser) { pollUser.Accepted = true; _context.Entry(pollUser).Property("Accepted").IsModified = true; await _context.SaveChangesAsync(); return(CreatedAtAction("GetPollUser", new { id = pollUser.PollUserID }, pollUser)); }
public ActionResult <IEnumerable <PollUserInvite> > InviteUserToPoll(int pollID, int userID) { //get the poll var poll = _context.Polls.Find(pollID); //get the user var user = _context.Users.Include(e => e.PollUserInvites).Include(e => e.PollUsers).SingleOrDefault(e => e.UserID == userID); if (poll != null && user != null) { List <PollUserInvite> userinvites = new List <PollUserInvite>(); userinvites.AddRange(user.PollUserInvites.Where(e => e.PollID == pollID)); List <PollUser> pollusers = new List <PollUser>(); pollusers.AddRange(user.PollUsers.Where(e => e.PollID == pollID)); //check if the user is already invited to this poll if (userinvites.Count > 0 || pollusers.Count > 0) { return(BadRequest()); } //add pollinvite PollUserInvite pollUserInvite = new PollUserInvite() { Poll = poll, PollID = pollID }; user.PollUserInvites.Add(pollUserInvite); _context.Entry(user).State = EntityState.Modified; _context.SaveChanges(); return(Ok()); } else { return(NotFound()); } }
public async Task <ActionResult <UserSelection> > PutUserSelection(Guid id, UserSelection userSelection) { if (id != userSelection.Id) { return(BadRequest()); } var selectionToUpdate = await _context.UserSelections.FindAsync(id); if (selectionToUpdate == null) { return(NotFound()); } selectionToUpdate.DateSelections = userSelection.DateSelections.OrderBy(ds => ds.Date).ToList(); selectionToUpdate.Name = userSelection.Name; _context.Entry(selectionToUpdate).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserSelectionExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <Poll> > GetPollAsync(Guid id) { var poll = await _context.Polls.FindAsync(id); if (poll == null) { return(NotFound()); } await _context.Entry(poll).Collection(p => p.UserSelections).LoadAsync(); poll.UserSelections.ForEach(us => us.DateSelections = us.DateSelections.OrderBy(ds => ds.Date).ToList()); return(poll); }
public void AddOneVote(Option option) { option.Votes++; _context.Entry(option).State = EntityState.Modified; }