Example #1
0
        public IEnumerable <ReceivedContactRequestDto> GetReceivedRequests(User currentUser)
        {
            var reqs = _context.ContactRequests.Where(x => x.RequesteeId == currentUser.Id).ToList();

            var receivedRequests = new List <ReceivedContactRequestDto>();

            foreach (var r in reqs)
            {
                var user = _context.ChatUsers.Find(r.RequesterId);

                ReceivedContactRequestDto rr = null;

                if (user != null)
                {
                    rr = new ReceivedContactRequestDto
                    {
                        Id            = r.Id,
                        RequesteeId   = r.RequesteeId,
                        RequesterId   = r.RequesterId,
                        FullName      = user.FullName,
                        ProfileImgUrl = user.ProfileImgUrl
                    };
                }

                if (rr != null)
                {
                    receivedRequests.Add(rr);
                }
            }


            return(receivedRequests);
        }
Example #2
0
        public ReceivedContactRequestDto AcceptContactRequest(ReceivedContactRequestDto req)
        {
            var rec = _context.ContactRequests.Find(req.Id);

            if (rec != null)
            {
                var newContact1 = new AcceptedContact();
                newContact1.UserId    = req.RequesterId;
                newContact1.ContactId = req.RequesteeId;

                _context.AcceptedContacts.Add(newContact1);

                var newContact2 = new AcceptedContact();
                newContact2.UserId    = req.RequesteeId;
                newContact2.ContactId = req.RequesterId;

                _context.AcceptedContacts.Add(newContact2);

                _context.ContactRequests.Remove(rec);

                _context.SaveChanges();
            }

            return(req);
        }
        public IActionResult AcceptContactRequest([FromBody] ReceivedContactRequestDto req)
        {
            var user = GetCurrentUser();

            if (user.Id == req.RequesteeId)
            {
                _contactService.AcceptContactRequest(req);

                var ex = _contactService.GetConversationForContact(user.Id, req.RequesterId);
                if (ex == null)
                {
                    var conv = _contactService.CreateConversation(req.RequesterId, req.RequesteeId);
                }

                _hubservice.AcceptContactRequest(user.Id.ToString(), user.FullName, req.RequesterId.ToString());
            }

            return(Ok(req));
        }