Exemple #1
0
        public async Task <IActionResult> Edit(int id, [Bind("pendingId,lookingId,seekingId")] pendingMatch pendingMatch)
        {
            if (id != pendingMatch.pendingId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(pendingMatch);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!pendingMatchExists(pendingMatch.pendingId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(pendingMatch));
        }
Exemple #2
0
        public async Task <IActionResult> Create([Bind("pendingId,lookingId,seekingId")] pendingMatch pendingMatch)
        {
            var userName = await _context.users.Where(u => u.UserID == pendingMatch.lookingId).Select(u => u.userName).SingleAsync();

            if (ModelState.IsValid)
            {
                var existing = from e in _context.pendingMatch
                               select e;

                var friend = from f in _context.users
                             select f;

                var pending = from p in _context.pendingMatch
                              select p;

                var temp = friend.Where(f => f.UserID == pendingMatch.lookingId);

                friend = friend.Where(f => f.FriendCode == pendingMatch.seekingId);

                existing = existing.Where(e => e.lookingId == friend.Single().UserID&& e.seekingId == temp.Single().FriendCode);

                if (pendingMatch.lookingId == friend.Single().UserID)
                {
                    return(View(pendingMatch));
                }
                else if (existing.Count() == 0)
                {
                    _context.Add(pendingMatch);
                    await _context.SaveChangesAsync();
                }
                else
                {
                    friendListController flc   = new friendListController(_context);
                    friendList           fren1 = new friendList();
                    friendList           fren2 = new friendList();
                    var usr = from u in _context.users
                              select u;
                    fren1.UserID     = pendingMatch.lookingId;
                    fren1.FriendCode = usr
                                       .Where(u => u.FriendCode == pendingMatch.seekingId)
                                       .Select(u => u.FriendCode)
                                       .Single();
                    fren2.UserID     = friend.Single().UserID;
                    fren2.FriendCode = usr
                                       .Where(u => u.UserID == pendingMatch.lookingId)
                                       .Select(u => u.FriendCode)
                                       .Single();
                    await flc.Create(fren1);

                    await flc.Create(fren2);

                    var remove = from u in _context.pendingMatch
                                 select u;
                    var remID = remove
                                .Where(u => u.lookingId == fren2.UserID)
                                .Select(u => u.pendingId)
                                .Single();
                    await DeleteConfirmed(remID);
                }
            }
            //return RedirectToAction(nameof(Index));
            string url = string.Format("/userlogon/index?username={0}", userName);

            return(Redirect(url));
        }