예제 #1
0
        public IAllianceUserRequests GetRequestsAllianceForMyAlliance(IDbConnection connection, int senderUserId)
        {
            var result = new AllianceUserRequests(MessageSourceType.IsUser);
            var data   = _armCache.LocalOperation(connection, col =>
            {
                return(col.Where(i => i.FromId == senderUserId && i.SourceType == MessageSourceType.IsUser ||
                                 i.ToId == senderUserId && i.SourceType == MessageSourceType.IsAlliance)
                       .OrderByDescending(i => i.DateCreate)
                       .ToList());
            });
            var allianceGroup = new Dictionary <int, List <AllianceRequestMessageDataModel> >();

            foreach (var request in data)
            {
                if (!allianceGroup.ContainsKey(request.ToId) && request.SourceType == MessageSourceType.IsUser ||
                    !allianceGroup.ContainsKey(request.FromId) && request.SourceType == MessageSourceType.IsAlliance)
                {
                    allianceGroup.Add(request.SourceType == MessageSourceType.IsUser ? request.ToId : request.FromId,
                                      new List <AllianceRequestMessageDataModel> {
                        request
                    });
                }
                else
                {
                    allianceGroup[request.SourceType == MessageSourceType.IsUser
                        ? request.ToId
                        : request.FromId].Add(request);
                }
            }

            result.Requests = allianceGroup.Select(group =>
            {
                var allianceAccepted = ArmAllianceAcceptedStatus.NoAction;
                if (group.Value.Any(i => i.AllianceAccepted == ArmAllianceAcceptedStatus.Accept))
                {
                    allianceAccepted = ArmAllianceAcceptedStatus.Accept;
                }
                else if (group.Value.Any(i => i.AllianceAccepted == ArmAllianceAcceptedStatus.Reject))
                {
                    allianceAccepted = ArmAllianceAcceptedStatus.Reject;
                }
                var userAccepted = group.Value.Any(i => i.UserAccepted);
                var groupName    = group.Value.First(i => i.SourceType == MessageSourceType.IsUser).ToName;

                return(new AllianceUserRequestItem
                {
                    GroupName = groupName,
                    GroupId = group.Key,
                    Messages = group.Value.OrderBy(i => i.DateCreate).ToList(),
                    AllianceAccepted = allianceAccepted,
                    UserAccepted = userAccepted
                });
            }).ToList();


            result.SetComplexButtonView();
            return(result);
        }
        public IAllianceUserRequests GetAllianceUserRequests(IDbConnection connection, AllianceUserDataModel allianceUserManager, AllianceRoleDataModel role = null)
        {
            if (role == null)
            {
                role = AllianceRoleHelper.GetByRoleId(allianceUserManager.RoleId);
            }
            if (!role.AcceptNewMembers)
            {
                return(null);
            }
            var aur = new AllianceUserRequests(MessageSourceType.IsAlliance)
            {
                Requests = GetRequestsAllianceForAllianceManage(connection, allianceUserManager, role)
            };

            aur.SetComplexButtonView();
            return(aur);
        }