Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
                }
            }
        }
        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));
        }