示例#1
0
        public async Task <IHttpActionResult> PostRejectFriendRequest(int friendId)
        {
            User user = CurrentUser;

            if (user == null)
            {
                return(NotFound());
            }

            UsersFriend friendship = await db.UsersFriends.FirstOrDefaultAsync(uf =>
                                                                               uf.UserId == friendId &&
                                                                               uf.FriendId == user.UserId &&
                                                                               uf.IsConfirmed == false);

            if (friendship == null)
            {
                return(NotFound());
            }

            db.UsersFriends.Remove(friendship);

            await db.SaveChangesAsync();

            return(Ok());
        }
示例#2
0
        public async Task <IHttpActionResult> PostConfirmRequest(int friendId)
        {
            User user = CurrentUser;

            if (user == null)
            {
                return(NotFound());
            }

            UsersFriend friendship = await db.UsersFriends
                                     .FirstOrDefaultAsync(uf =>
                                                          uf.UserId == friendId &&
                                                          uf.FriendId == user.UserId &&
                                                          uf.IsConfirmed == false);

            if (friendship == null)
            {
                return(NotFound());
            }

            friendship.IsConfirmed = true;

            db.Entry(friendship).State = EntityState.Modified;

            await db.SaveChangesAsync();

            return(Ok());
        }