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 void UpdateObjective(ObjectiveEditorViewModel viewModel, ObjectivePart objectivePart)
        {
            foreach (var objectiveResultPreset in objectivePart.ObjectiveResultPresets)
            {
                _objectiveResultPresetRepository.Delete(objectiveResultPreset);
            }
            objectivePart.ObjectiveResultPresets.Clear();

            for (int i = 0; i < viewModel.ObjectiveResultPresets.Count; i++)
            {
                var objectiveResultPreset = viewModel.ObjectiveResultPresets[i];

                var newPreset = new ObjectiveResultPresetRecord
                {
                    DisplayName         = objectiveResultPreset.DisplayName,
                    Points              = objectiveResultPreset.Points,
                    Position            = i,
                    ObjectivePartRecord = objectivePart.Record,
                };

                _objectiveResultPresetRepository.Create(newPreset);

                objectivePart.ObjectiveResultPresets.Add(newPreset);
            }

            var game = _gameService.Get(viewModel.GameId);

            objectivePart.Game = game.Record;
        }
Exemple #3
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);
        }
Exemple #4
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);
        }
Exemple #6
0
 private void FixGamePartRecordReference(ObjectivePart objective)
 {
     if (objective.Game == null)
     {
         var common = objective.As <CommonPart>();
         if (common != null && common.Container != null)
         {
             var game = _gameService.Value.Get(common.Container.Id);
             if (game != null)
             {
                 objective.Game = game.Record;
                 _repository.Update(objective.Record);
                 _repository.Flush();
             }
         }
     }
 }
Exemple #7
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 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);
                }
            }
        }
Exemple #9
0
        public ActionResult List(int?objectiveId)
        {
            ObjectivePart objective = objectiveId != null?_objectiveService.Get(objectiveId.Value, VersionOptions.Latest) : null;

            if (objective != null)
            {
                var objectiveResults = _objectiveResultService.Get(objective, VersionOptions.Latest);
                var list             = Services.New.List();

                list.AddRange(objectiveResults.Select(objectiveResult => Services.ContentManager.BuildDisplay(objectiveResult, "SummaryAdmin")));

                dynamic viewModel = Services.New.ViewModel()
                                    .ContentItems(list)
                                    .Objective(objective);

                return(View((object)viewModel));
            }
            else
            {
                return(HttpNotFound());
            }
        }
 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 static string ChooseObjectiveResultTeam(this UrlHelper urlHelper, ObjectivePart objectivePart)
 {
     return(urlHelper.Action("ChooseTeam", "ObjectiveResultAdmin", new { area = "DeSjoerd.Competition", objectiveId = objectivePart.ContentItem.Id, ReturnUrl = GetReturnUrl() }));
 }
 public static string ObjectiveResults(this UrlHelper urlHepler, ObjectivePart objectivePart)
 {
     return(urlHepler.Action("List", "ObjectiveResultAdmin", new { area = "DeSjoerd.Competition", objectiveId = objectivePart.ContentItem.Id }));
 }
Exemple #13
0
 public static string QuestionObjectiveSubmit(this UrlHelper url, ObjectivePart objective)
 {
     return(url.Action("Submit", "QuestionObjective", new { id = objective.ContentItem.Id, ReturnUrl = GetReturnUrl(), area = "DeSjoerd.Competition.ActionObjectives" }));
 }
        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));
        }