Ejemplo n.º 1
0
        public (bool status, string message) Request(Guid userSender, Guid userReciever)
        {
            try
            {
                bool   _status  = true;
                string _message = "Success";

                _friendRequestRepository.BeginTransaction();

                if (_userApiService.UserExist(userSender) == true && _userApiService.UserExist(userReciever) == true)
                {
                    var request = new FriendRequest
                    {
                        Id           = Guid.NewGuid(),
                        UserSender   = userSender,
                        UserReciever = userReciever,
                        Status       = _activityStatusRepository.Get(x => x.Name.Equals(Global.Status.Request)).FirstOrDefault().Id
                    };

                    _friendRequestRepository.Insert(request);

                    var relationship = new FriendRelationship
                    {
                        Id = Guid.NewGuid(),
                        FriendRequestId = request.Id,
                        Status          = _activityStatusRepository.Get(x => x.Name.Equals(Global.Status.Pending)).FirstOrDefault().Id
                    };

                    _friendRelationshipRepository.Insert(relationship);

                    _friendRequestRepository.Save();
                }
                else
                {
                    _status  = false;
                    _message = "User Sender or Reciever not exist";
                }

                _friendRequestRepository.CommitTransaction();

                return(_status, _message);
            }
            catch (Exception ex)
            {
                _friendRequestRepository.RollbackTransaction();
                throw ex;
            }
        }
Ejemplo n.º 2
0
        public List <AccountUserDto> ListUserConversation(Guid idUser)
        {
            try
            {
                var result = new List <AccountUserDto>();

                if (_userApiService.UserExist(idUser) == true)
                {
                    var dataConversation = _conversationRepository.GetInclude(x => x.UserCreator == idUser && x.IsActive == true,
                                                                              includes:
                                                                              source =>
                                                                              source.Include(x => x.Participant)
                                                                              .Include(x => x.Messages)
                                                                              ).ToList();

                    var readMessages = dataConversation.SelectMany(x => x.Participant).ToList();
                    readMessages.ForEach(item =>
                    {
                        item.Status = _activityStatusRepository.Get(x => x.Name.Equals(Global.Status.Read)).FirstOrDefault().Id;
                    });

                    _participantRepository.UpdateRange(readMessages);
                    _participantRepository.Save();

                    var userConversation = dataConversation
                                           .SelectMany(x => x.Participant)
                                           .Select(x => x.UserAccount)
                                           .ToList();

                    result = _userApiService.GetUsers(userConversation);
                }

                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }