public (bool status, string message) Approve(Guid idRequest)
        {
            try
            {
                bool   _status  = true;
                string _message = "Success";

                _friendRequestRepository.BeginTransaction();

                var approveRequest = _friendRequestRepository.GetInclude(x => x.Id == idRequest,
                                                                         includes: source => source.Include(x => x.FriendRelationship)
                                                                         ).SingleOrDefault();

                if (approveRequest != null)
                {
                    approveRequest.Status = _activityStatusRepository.Get(x => x.Name.Equals(Global.Status.Accepted)).FirstOrDefault().Id;
                    _friendRequestRepository.Update(approveRequest);

                    var relationship = approveRequest.FriendRelationship.FirstOrDefault();
                    relationship.Status = _activityStatusRepository.Get(x => x.Name.Equals(Global.Status.Accepted)).FirstOrDefault().Id;
                    _friendRelationshipRepository.Update(relationship);

                    _friendRequestRepository.Save();
                }
                else
                {
                    _status  = false;
                    _message = "Request not found";
                }

                _friendRequestRepository.CommitTransaction();

                return(_status, _message);
            }
            catch (Exception ex)
            {
                _friendRequestRepository.RollbackTransaction();
                throw ex;
            }
        }
Esempio 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;
            }
        }