Пример #1
0
        private List <IOfficerOut> _getOfficerOutList(List <IUserOfficerOut> userOfficers)
        {
            var outOfficers = new List <IOfficerOut>();

            if (userOfficers == null)
            {
                return(outOfficers);
            }
            foreach (var baseOfficer in OfficerHelper.GetOfficers())
            {
                var type  = baseOfficer.Type;
                var users = userOfficers.Where(i => i.Type == type).ToList();
                if (users.Count > 2)
                {
                    throw new NotImplementedException("users.Count > 2");
                }

                var             elected    = users.Single(i => i.Elected);
                IUserOfficerOut app        = null;
                var             appUserOut = users.SingleOrDefault(i => !i.Elected);
                if (appUserOut != null)
                {
                    app = appUserOut;
                }
                else if (type != OfficerTypes.President)
                {
                    app = new UserOfficerOut(false, type);
                }
                var userOfficer = new OfficerOut(baseOfficer, elected, app);
                outOfficers.Add(userOfficer);
            }
            return(outOfficers.OrderBy(i => i.Type).ToList());
        }
        private List <IUserOfficerOut> _buildOfficers(IDbConnection connection, int startRegister,
                                                      List <WinnerCandidat> winners)
        {
            var officers       = new List <IUserOfficerOut>();
            var endOfficerTime = EndVoteTime;
            var insertOfficers = new List <c_officer>
            {
                new c_officer
                {
                    userId      = winners[0].UserId,
                    allianceId  = winners[0].AllianceId,
                    elected     = true,
                    officerType = (byte)OfficerTypes.President,
                    dateStart   = startRegister,
                    dateEnd     = endOfficerTime
                },
                new c_officer
                {
                    userId      = winners[1].UserId,
                    allianceId  = winners[1].AllianceId,
                    elected     = true,
                    officerType = (byte)OfficerTypes.Atacker,

                    dateStart = startRegister,
                    dateEnd   = endOfficerTime
                },
                new c_officer
                {
                    userId      = winners[2].UserId,
                    allianceId  = winners[2].AllianceId,
                    elected     = true,
                    officerType = (byte)OfficerTypes.Protector,
                    dateStart   = startRegister,
                    dateEnd     = endOfficerTime
                },
                new c_officer
                {
                    userId      = winners[3].UserId,
                    allianceId  = winners[3].AllianceId,
                    elected     = true,
                    officerType = (byte)OfficerTypes.Supporter,
                    dateStart   = startRegister,
                    dateEnd     = endOfficerTime
                }
            };

            insertOfficers = (List <c_officer>)_officerRepository.AddOrUpdate(connection, insertOfficers);

            var president = insertOfficers.Single(i => i.userId == winners[0].UserId);
            var atacker   = insertOfficers.Single(i => i.userId == winners[1].UserId);
            var protector = insertOfficers.Single(i => i.userId == winners[2].UserId);
            var supporter = insertOfficers.Single(i => i.userId == winners[3].UserId);


            var presidentOut = new UserOfficerOut(_officerRepository.ConvertToWorkModel(president));

            presidentOut.UserName      = winners[0].UserName;
            presidentOut.UserAvatar    = Avatar.GetFileUrls(winners[0].UserAvatar);
            presidentOut.AllianceName  = winners[0].AllianceName;
            presidentOut.AllianceLabel = Label.GetFileUrls(winners[0].AllianceLabel);


            var atakerOut = new UserOfficerOut(_officerRepository.ConvertToWorkModel(atacker));

            atakerOut.UserName      = winners[1].UserName;
            atakerOut.UserAvatar    = Avatar.GetFileUrls(winners[1].UserAvatar);
            atakerOut.AllianceName  = winners[1].AllianceName;
            atakerOut.AllianceLabel = Label.GetFileUrls(winners[1].AllianceLabel);

            var defendorOut = new UserOfficerOut(_officerRepository.ConvertToWorkModel(protector));

            defendorOut.UserName      = winners[2].UserName;
            defendorOut.UserAvatar    = Avatar.GetFileUrls(winners[2].UserAvatar);
            defendorOut.AllianceName  = winners[2].AllianceName;
            defendorOut.AllianceLabel = Label.GetFileUrls(winners[2].AllianceLabel);

            var suporterOut = new UserOfficerOut(_officerRepository.ConvertToWorkModel(supporter));

            suporterOut.UserName      = winners[0].UserName;
            suporterOut.UserAvatar    = Avatar.GetFileUrls(winners[3].UserAvatar);
            suporterOut.AllianceName  = winners[3].AllianceName;
            suporterOut.AllianceLabel = Label.GetFileUrls(winners[3].AllianceLabel);

            officers.Add(presidentOut);
            officers.Add(atakerOut);
            officers.Add(defendorOut);
            officers.Add(suporterOut);
            officers.Add(new UserOfficerOut(false, OfficerTypes.Atacker));
            officers.Add(new UserOfficerOut(false, OfficerTypes.Protector));
            officers.Add(new UserOfficerOut(false, OfficerTypes.Supporter));

            return(officers);
        }