示例#1
0
 public void SetRole(AllianceRoleDataModel repoRole)
 {
     Id                 = repoRole.Id;
     RoleName           = repoRole.RoleName;
     EditAllianceInfo   = repoRole.EditAllianceInfo;
     MessageRead        = repoRole.MessageRead;
     MessageSend        = repoRole.MessageSend;
     ShowManage         = repoRole.ShowManage;
     SetTech            = repoRole.SetTech;
     CanManagePermition = repoRole.CanManagePermition;
     AcceptNewMembers   = repoRole.AcceptNewMembers;
     DeleteMembers      = repoRole.DeleteMembers;
 }
示例#2
0
        public AllianceTechesOut(AllianceRoleDataModel userRole, Dictionary <TechType, ItemProgress> dbAllianceTeches)
        {
            CanUpgrade = userRole.SetTech;
            var techService = new BattleTeches(dbAllianceTeches);
            var teches      = techService.GetTeches(false);

            teches.ForEach(i =>
            {
                i.Value.Progress.Advanced = i.Value.GetPropertiesView(true);
            });
            Teches = techService.ConvertToTechesOut(true);
            Teches.ForEach(i =>
            {
                i.Value.CalcResultPrice(false);
            });

            SetComplexButtonView();
        }
示例#3
0
        public AllianceTechesOut GetAllianceTechesOut(IDbConnection connection, int allianceId, AllianceRoleDataModel currentUserRole)
        {
            var techProgress = GetAllianceTech(connection, allianceId);

            return(new AllianceTechesOut(currentUserRole, techProgress.Teches));
        }
示例#4
0
        public IList <AllianceRequestMessageDataModel> RejectRequestToAlliance(IDbConnection connection, AllianceUserDataModel currentUser, int rejectUserId, AllianceRoleDataModel role = null)
        {
            var permition = role ?? AllianceRoleHelper.GetByRoleId(currentUser.RoleId);

            if (!permition.AcceptNewMembers)
            {
                throw new SecurityException(Error.NotPermitted);
            }
            var data = _armCache.LocalOperation(connection, col =>
            {
                return(col.Where(i =>
                                 i.FromId == currentUser.AllianceId && i.ToId == rejectUserId &&
                                 i.SourceType == MessageSourceType.IsAlliance ||
                                 i.FromId == rejectUserId && i.ToId == currentUser.AllianceId &&
                                 i.SourceType == MessageSourceType.IsUser).ToList());
            });

            if (!data.Any())
            {
                return(data);
            }

            foreach (var request in data)
            {
                request.AllianceAccepted = ArmAllianceAcceptedStatus.Reject;
            }
            var dbData       = _armRepo.AddOrUpdateAllModels(connection, data);
            var newData      = _armCache.UpdateLocalItems(connection, dbData);
            var alData       = newData.FirstOrDefault(i => i.FromId == currentUser.AllianceId && i.SourceType == MessageSourceType.IsAlliance);
            var rejectedUser = data.First(i => i.FromId == rejectUserId && i.SourceType == MessageSourceType.IsUser);

            var armModel = new AllianceRequestMessageDataModel
            {
                AllianceAccepted = ArmAllianceAcceptedStatus.Reject,
                ToId             = rejectUserId,
                DateCreate       = UnixTime.UtcNow(),
                FromId           = currentUser.AllianceId,
                Message          = "Rejected",
                UserAccepted     = false,
                SourceType       = MessageSourceType.IsAlliance,
                ToName           = rejectedUser.FromName
            };

            armModel.AllianceAccepted = ArmAllianceAcceptedStatus.Reject;
            if (alData == null)
            {
                var allaince = GetAllianceById(connection, currentUser.AllianceId, false);
                if (allaince == null)
                {
                    throw new NullReferenceException(Error.AllianceNotExist);
                }
                armModel.FromName    = allaince.Name;
                armModel.CreatorIcon = allaince.Images.Icon;
            }
            else
            {
                armModel.FromName    = alData.FromName;
                armModel.CreatorIcon = alData.CreatorIcon;
            }
            var messageForUser = AddArmItem(connection, armModel);

            newData.Add(messageForUser);
            return(newData);
        }
示例#5
0
        public IList <AllianceUserRequestItem> GetRequestsAllianceForAllianceManage(IDbConnection connection, AllianceUserDataModel allianceUserManager, AllianceRoleDataModel role = null)
        {
            var permition = role ?? AllianceRoleHelper.GetByRoleId(allianceUserManager.RoleId);

            if (!permition.AcceptNewMembers)
            {
                throw new SecurityException(Error.NotPermitted);
            }

            var data = _armCache.LocalOperation(connection, col =>
            {
                var collection = col.Where(i => i.AllianceAccepted != ArmAllianceAcceptedStatus.Reject &&
                                           (i.FromId == allianceUserManager.AllianceId &&
                                            i.SourceType == MessageSourceType.IsAlliance ||
                                            i.ToId == allianceUserManager.AllianceId &&
                                            i.SourceType == MessageSourceType.IsUser))
                                 .OrderByDescending(i => i.DateCreate)
                                 .ToList();
                return(collection);
            });

            var usersGroups = new Dictionary <int, List <AllianceRequestMessageDataModel> >();

            foreach (var request in data)
            {
                if (!usersGroups.ContainsKey(request.ToId) && request.SourceType == MessageSourceType.IsAlliance ||
                    !usersGroups.ContainsKey(request.FromId) && request.SourceType == MessageSourceType.IsUser)
                {
                    usersGroups.Add(request.SourceType == MessageSourceType.IsAlliance ? request.ToId : request.FromId,
                                    new List <AllianceRequestMessageDataModel> {
                        request
                    });
                }
                else
                {
                    usersGroups[request.SourceType == MessageSourceType.IsAlliance ? request.ToId : request.FromId]
                    .Add(request);
                }
            }
            var result = usersGroups.Select(group =>
            {
                var allianceAccepted = ArmAllianceAcceptedStatus.NoAction;
                if (group.Value.Any(i => i.AllianceAccepted == ArmAllianceAcceptedStatus.Accept))
                {
                    allianceAccepted = ArmAllianceAcceptedStatus.Accept;
                }
                var userAccepted = group.Value.Any(i => i.UserAccepted);
                var groupName    = group.Value.First(i => i.SourceType == MessageSourceType.IsUser).FromName;

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

            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);
        }
        private TabAllianceManageOut _getManageTab(IDbConnection connection, AllianceUserDataModel currentUserAllianceMember, AllianceRoleDataModel role)
        {
            var manageAlliance = new TabAllianceManageOut();

            if (role.Id == (byte)AllianceRoles.Creator)
            {
                manageAlliance.CanDeleteAlliance = true;
            }
            manageAlliance.AllianceUserRequests = GetAllianceUserRequests(connection, currentUserAllianceMember, role);
            return(manageAlliance);
        }
 public UpdateUserRoleModel(int allianceId, int targetUserId, AllianceRoleDataModel newRole)
 {
     AllianceId   = allianceId;
     TargetUserId = targetUserId;
     NewRole      = newRole;
 }
示例#9
0
 public static ChannelConnectionDataModel CreateModelByAllianceChannel(this ChannelDataModel allianceChannel, AllianceUserDataModel allianceUser, AllianceRoleDataModel role)
 {
     return(new ChannelConnectionDataModel
     {
         UserId = allianceUser.UserId,
         ChannelId = allianceChannel.Id,
         Password = allianceChannel.Password,
         MessageRead = role.MessageRead,
         MessageSend = role.MessageSend,
         ChannelType = allianceChannel.ChannelType
     });
 }
示例#10
0
 public AllianceRoleDataModel AddOrUpdateAllianceRole(IDbConnection connection, AllianceRoleDataModel dataModel)
 {
     return(_aRolesCache.UpdateLocalItem(connection, _aRolesRepo.AddOrUpdateeModel(connection, dataModel)));
 }
示例#11
0
        public AllianceChannelOut GetAllianceChannelOut(IDbConnection connection, int allianceId, int currentUserId, AllianceRoleDataModel allianceUserRole, int skip = 0)
        {
            if (!allianceUserRole.MessageRead)
            {
                return(null);
            }
            AllianceChannelOut result = (AllianceChannelOut)null;
            var allianceChannelType   = (byte)ChannelTypes.Alliance;
            //todo передалать на процедуру
            var channelData = _channelConnRepo.Provider.GetAllianceChannelDb(connection, allianceId);

            if (channelData == null)
            {
                throw new NullReferenceException(Error.ChannelNotExist);
            }
            var connectedData        = _channelConnRepo.GetUserConnectedChannls(connection, currentUserId, allianceChannelType);
            var filtredConnectedData = connectedData.Where(i => i.ChannelData.Id == channelData.Id && i.ChannelData.password == channelData.password).ToList();

            if (!filtredConnectedData.Any())
            {
                throw new SecurityException(Error.NotPermitted);
            }
            if (filtredConnectedData.Count != 1)
            {
                throw new NotImplementedException("GetAllianceChannelOut: filtredConnectedData.Count!= 1");
            }

            var conn = filtredConnectedData[0];

            if (!conn.MessageRead)
            {
                return(null);
            }
            if (allianceUserRole.MessageSend != conn.MessageSend)
            {
                throw new NotImplementedException(Error.NotEquals);
            }

            var allianceChannel    = channelData.ConvertToWorkModel();
            var allianceChannelOut = new AllianceChannelOut(allianceChannel);

            allianceChannelOut.SetMessages(connection, _channelMessageRepo, skip);

            allianceChannelOut.SetBtnSend(allianceUserRole.MessageSend);
            result = allianceChannelOut;
            return(result);
        }
示例#12
0
        public IPlanshetViewData InitialPlanshetChannels(IDbConnection connection, int currentUserId, int allianceId, AllianceRoleDataModel allianceUserRole)
        {
            var data = new ChannelsTabsData();

            data.SetChannelsTabsData(connection, _channelRepo, _channelMessageRepo, _channelConnRepo, currentUserId, allianceId, allianceUserRole.MessageSend);
            return(data.GetPlanshet());
        }
示例#13
0
        internal static async Task UpdateAllianceGroupsByPermitionsAsync(this ConnectionUser connectionUser,
                                                                         IGroupManager groups, AllianceRoleDataModel oldUserRole, AllianceRoleDataModel newRole)
        {
            if (oldUserRole.AcceptNewMembers != newRole.AcceptNewMembers)
            {
                if (newRole.AcceptNewMembers)
                {
                    await connectionUser.AddOrReplaceAllianceRecrutManagerGroupAsync(groups);
                }
                else
                {
                    await connectionUser.RemoveAllianceRecrutManagerGroupNameAsync(groups);
                }
            }


            //todo удалить если не потребуется
            //не удалять коменты!
            //if (oldUserRole.CanManagePermition !=  newRole.CanManagePermition)
            //{
            //    //todo  если пявится группа  только для менеджеров
            //}
            //if (oldUserRole.DeleteMembers != newRole.DeleteMembers)
            //{
            //    //todo  если пявится группа
            //}
            //if (oldUserRole.EditAllianceInfo != newRole.EditAllianceInfo)
            //{
            //    //todo  если пявится группа

            //}
            //if (oldUserRole.MessageRead != newRole.MessageRead)
            //{
            //    //todo  когда пявится группа
            //}
            //if (oldUserRole.MessageSend != newRole.MessageSend)
            //{
            //    //todo  когда пявится группа

            //}
            //if (oldUserRole.SetTech != newRole.SetTech)
            //{
            //    //todo  если пявится группа
            //}
            //if (oldUserRole.ShowManage != newRole.ShowManage)
            //{
            //    //todo  если пявится группа
            //}
        }