public void PublishUser(TeamPart part)
        {
            var foundUser = _membershipService.GetUser(part.UserName);

            if (foundUser != null && foundUser.Id != part.Id)
            {
                const string nameFormat = "{0}{1}";
                int          n          = 2;
                string       newUserName;
                do
                {
                    newUserName = string.Format(nameFormat, part.UserName, n);
                    n++;

                    foundUser = _membershipService.GetUser(newUserName);
                } while (foundUser != null);

                part.UserName = newUserName;
            }

            var userPart = part.As <UserPart>();

            userPart.UserName           = part.UserName;
            userPart.NormalizedUserName = part.UserName.ToLowerInvariant();
            userPart.Email = part.UserName;
            userPart.RegistrationStatus = UserStatus.Approved;
            userPart.EmailStatus        = UserStatus.Approved;

            userPart.Record.Password       = part.Password;
            userPart.Record.PasswordFormat = MembershipPasswordFormat.Clear;
            userPart.Record.PasswordSalt   = null;
        }
        private void SetParts(BuildShapeContext context)
        {
            var tempPartTemp = context.ContentItem.As <TeamPart>();

            if (tempPartTemp != null)
            {
                this.teamPart = tempPartTemp;
            }

            var tempBusinessUnitPart = context.ContentItem.As <BusinessUnitPart>();

            if (tempBusinessUnitPart != null)
            {
                this.businessUnitPart = tempBusinessUnitPart;
            }

            var tempTicketPart = context.ContentItem.As <TicketPart>();

            if (tempTicketPart != null)
            {
                this.ticketPart = tempTicketPart;
            }

            if (this.contentItem == null)
            {
                this.contentItem = context.ContentItem;
            }

            var contentItemPermissionPart = context.ContentItem.As <ContentItemPermissionPart>();

            if (contentItemPermissionPart != null)
            {
                this.permissionParts.Add(contentItemPermissionPart);
            }
        }
        public IEnumerable <ObjectiveResultPart> GetResultsOfTeam(TeamPart team, VersionOptions versionOptions)
        {
            Argument.ThrowIfNull(team, "team");

            var teamResultIds = _objectiveResultRepository.Fetch(result => result.TeamPartRecord.ContentItemRecord.Id == team.ContentItem.Id).Select(result => result.ContentItemRecord.Id);

            return(_contentManager.GetMany <ObjectiveResultPart>(teamResultIds, versionOptions, new QueryHints()));
        }
        private void OnPublishingTeam(PublishContentContext context, TeamPart part)
        {
            var userName = part.UserName;

            _teamService.Value.PublishUser(part);

            if (userName != part.UserName)
            {
                _services.Value.Notifier.Warning(T("UserNames in conflict. \"{0}\" is already set for another user so now it has the UserName \"{1}\"",
                                                   userName, part.UserName));
            }
        }
Example #5
0
        public void SubmitVideo(ObjectivePart objective, TeamPart team, string videoUrl)
        {
            Argument.ThrowIfNull(objective, "objective");
            Argument.ThrowIfNull(team, "team");
            Argument.ThrowIfNullOrEmpty(videoUrl, "videoUrl");


            var newSubmit = _actionSubmitService.NewActionSubmit <VideoSubmitPart>(objective, team, "VideoSubmit");

            newSubmit.VideoUrl = videoUrl;

            _contentManager.Create(newSubmit);
        }
Example #6
0
        public IContent NewActionSubmit(ObjectivePart objective, TeamPart team, string submitContentType)
        {
            var newSubmit = _contentManager.New <ActionSubmitPart>(submitContentType);

            if (newSubmit == null)
            {
                return(null);
            }

            newSubmit.Team      = team.Record;
            newSubmit.Objective = objective.Record;

            return(newSubmit);
        }
        private dynamic BuildSubmitList(ObjectivePart objective, TeamPart team, dynamic shapeHelper)
        {
            var submits = GetSubmitsOfTeam(objective, team);

            var list = shapeHelper.List(Classes: new [] { "small-block-grid-1", "large-block-grid-4" });

            list.AddRange(submits.Select(submit => {
                var shape = _contentManager.Value.BuildDisplay(submit, "Summary");
                shape.Classes.Add("th");
                return(shape);
            }));

            return(list);
        }
Example #8
0
        public void SubmitPhoto(ObjectivePart objective, TeamPart team, HttpPostedFileBase photo)
        {
            Argument.ThrowIfNull(objective, "objective");
            Argument.ThrowIfNull(team, "team");
            Argument.ThrowIfNull(photo, "photo");

            var path = Path.Combine("Submits", _slugService.Slugify(team.Title), _slugService.Slugify(objective.Title));

            var guid      = Guid.NewGuid().ToString();
            var extension = photo.FileName.Split('.').LastOrDefault() ?? string.Empty;

            string publicUrl  = null;
            var    succesfull = true;

            try
            {
                using (Image img = Image.FromStream(photo.InputStream))
                {
                    double ratio  = img.Height > 1024 ? 1024.0 / img.Height : 1.0;
                    int    height = (int)(ratio * img.Height);
                    int    width  = (int)(ratio * img.Width);
                    using (Bitmap bitmap = new Bitmap(img, width, height))
                    {
                        using (var memoryStream = new MemoryStream())
                        {
                            bitmap.Save(memoryStream, ImageFormat.Jpeg);
                            memoryStream.Position = 0;

                            publicUrl = _mediaService.UploadMediaFile(path, string.Format("{0}.{1}", guid, ".jpg"), memoryStream, false);
                        }
                    }
                }
            }
            catch (Exception)
            {
                succesfull = false;
            }
            if (succesfull)
            {
                var newSubmit = _actionSubmitService.NewActionSubmit <PhotoSubmitPart>(objective, team, "PhotoSubmit");
                newSubmit.PhotoUrl = publicUrl;
                _contentManager.Create(newSubmit);
            }
        }
        public void BuyHint(QuestionObjectivePart questionObjective, TeamPart team)
        {
            Argument.ThrowIfNull(questionObjective, "questionObjective");
            Argument.ThrowIfNull(team, "team");

            if (questionObjective.HasHint && !questionObjective.HintUsedByTeams.Any(t => t.TeamPartRecord.ContentItemRecord.Id == team.ContentItem.Id))
            {
                var teamUsedHint = new TeamUsedHintRecord
                {
                    QuestionObjectivePartRecord = questionObjective.Record,
                    TeamPartRecord = team.Record
                };

                _teamUsedHintRepository.Create(teamUsedHint);

                //questionObjective.HintUsedByTeams.Add(new TeamUsedHintRecord
                //{
                //    QuestionObjectivePartRecord = questionObjective.Record,
                //    TeamPartRecord = team.Record
                //});
            }
        }
        public void SubmitAnswer(ObjectivePart objective, TeamPart team, string answer)
        {
            Argument.ThrowIfNull(objective, "objective");
            Argument.ThrowIfNull(team, "team");
            Argument.ThrowIfNullOrEmpty(answer, "answer");

            var newSubmit = _actionSubmitService.NewActionSubmit <QuestionSubmitPart>(objective, team, "QuestionSubmit");

            newSubmit.Answer = answer.Trim();

            _contentManager.Create(newSubmit);

            var question = objective.As <QuestionObjectivePart>();

            if (question != null && question.AutoValidate)
            {
                var newActionSubmit = newSubmit.As <ActionSubmitPart>();

                var answers = question.Answers.ToList();
                if (answers.Any(a => a.Answer.Trim().ToLowerInvariant() == answer.Trim().ToLowerInvariant()))
                {
                    var resultPreset = objective.ObjectiveResultPresets.FirstOrDefault();

                    var points            = resultPreset.Points;
                    var resultDisplayName = resultPreset.DisplayName;

                    if (question.HintUsedByTeams.Any(teamHint => teamHint.TeamPartRecord.ContentItemRecord.Id == team.ContentItem.Id))
                    {
                        points -= question.HintPrice;
                    }

                    _actionSubmitService.Approve(newActionSubmit, resultDisplayName, points);
                }
                else
                {
                    _actionSubmitService.Reject(newActionSubmit);
                }
            }
        }
 public static string ObjectiveResultCreate(this UrlHelper urlHelper, TeamPart teamPart, ObjectivePart objectivePart)
 {
     return(urlHelper.Action("Create", "ObjectiveResultAdmin", new { area = "DeSjoerd.Competition", teamId = teamPart.ContentItem.Id, objectiveId = objectivePart.ContentItem.Id, ReturnUrl = GetReturnUrl() }));
 }
 public IEnumerable <ObjectiveResultPart> GetResultsOfTeam(TeamPart team)
 {
     return(GetResultsOfTeam(team, VersionOptions.Published));
 }
Example #13
0
    /// <summary>
    /// 注册部件
    /// </summary>
    protected virtual void registParts()
    {
        _list = new PlayerBasePart[17];
        int i = 0;

        system = new SystemPart();
        system.setMe(this);
        _list[i++] = system;

        func = new FuncPart();
        func.setMe(this);
        _list[i++] = func;

        activity = new ActivityPart();
        activity.setMe(this);
        _list[i++] = activity;

        role = new RolePart();
        role.setMe(this);
        _list[i++] = role;

        scene = new ScenePart();
        scene.setMe(this);
        _list[i++] = scene;

        character = new CharacterPart();
        character.setMe(this);
        _list[i++] = character;

        social = new SocialPart();
        social.setMe(this);
        _list[i++] = social;

        bag = new BagPart();
        bag.setMe(this);
        _list[i++] = bag;

        mail = new MailPart();
        mail.setMe(this);
        _list[i++] = mail;

        quest = new QuestPart();
        quest.setMe(this);
        _list[i++] = quest;

        guide = new GuidePart();
        guide.setMe(this);
        _list[i++] = guide;

        friend = new FriendPart();
        friend.setMe(this);
        _list[i++] = friend;

        equip = new EquipPart();
        equip.setMe(this);
        _list[i++] = equip;

        team = new TeamPart();
        team.setMe(this);
        _list[i++] = team;

        union = new UnionPart();
        union.setMe(this);
        _list[i++] = union;

        achievement = new AchievementPart();
        achievement.setMe(this);
        _list[i++] = achievement;

        pet = new PetPart();
        pet.setMe(this);
        _list[i++] = pet;
    }
 private IEnumerable <ActionSubmitPart> GetSubmitsOfTeam(ObjectivePart objective, TeamPart team)
 {
     return(_contentManager.Value.Query <ActionSubmitPart, ActionSubmitPartRecord>(VersionOptions.Published)
            .Where(submit => submit.ObjectivePartRecord == objective.Record && submit.TeamPartRecord == team.Record)
            .Join <CommonPartRecord>()
            .OrderByDescending(common => common.CreatedUtc).List());
 }
        public static T NewActionSubmit <T>(this IActionSubmitService actionSubmitService, ObjectivePart objective, TeamPart team, string submitContentType) where T : IContent
        {
            var newSubmit = actionSubmitService.NewActionSubmit(objective, team, submitContentType);

            return(newSubmit != null?newSubmit.As <T>() : default(T));
        }