Esempio n. 1
0
        public ActionResult Create(ModelType model)
        {
            if (model != null && this.ModelState.IsValid)
            {
                if (model.ProblemId.HasValue)
                {
                    var problem = this.Data.Problems.GetById(model.ProblemId.Value);
                    if (problem != null)
                    {
                        this.ValidateParticipant(model.ParticipantId, problem.ContestId);
                    }

                    var submissionType = this.GetSubmissionType(model.SubmissionTypeId.Value);
                    if (submissionType != null)
                    {
                        this.ValidateSubmissionContentLength(model, problem);
                        this.ValidateBinarySubmission(model, problem, submissionType);
                    }
                }

                if (this.ModelState.IsValid)
                {
                    var entity = model.GetEntityModel();
                    entity.Processed  = false;
                    entity.Processing = false;
                    this.BaseCreate(entity);
                    this.TempData.AddInfoMessage(Resource.Successful_creation_message);
                    return(this.RedirectToAction(GlobalConstants.Index));
                }
            }

            this.ViewBag.SubmissionAction = "Create";
            return(this.View(model));
        }
Esempio n. 2
0
        public ActionResult Update(ModelType model)
        {
            if (model.Id.HasValue)
            {
                if (!model.ProblemId.HasValue || !this.CheckIfUserHasProblemPermissions(model.ProblemId.Value))
                {
                    this.TempData[GlobalConstants.DangerMessage] = "Нямате привилегиите за това действие";
                    return(this.RedirectToAction("Index", "Contests", new { area = "Administration" }));
                }

                var submission = this.Data.Submissions.GetById(model.Id.Value);
                if (model.SubmissionTypeId.HasValue)
                {
                    var submissionType = this.Data.SubmissionTypes.GetById(model.SubmissionTypeId.Value);
                    if (submissionType.AllowBinaryFilesUpload && model.FileSubmission == null)
                    {
                        model.Content       = submission.Content;
                        model.FileExtension = submission.FileExtension;
                        if (this.ModelState.ContainsKey("Content"))
                        {
                            this.ModelState["Content"].Errors.Clear();
                        }
                    }
                }
            }

            if (this.ModelState.IsValid)
            {
                if (model.ProblemId.HasValue)
                {
                    var problem = this.Data.Problems.GetById(model.ProblemId.Value);
                    if (problem != null)
                    {
                        this.ValidateParticipant(model.ParticipantId, problem.ContestId);
                    }

                    var submissionType = this.GetSubmissionType(model.SubmissionTypeId.Value);
                    if (submissionType != null)
                    {
                        this.ValidateSubmissionContentLength(model, problem);
                        this.ValidateBinarySubmission(model, problem, submissionType);
                    }
                }

                if (this.ModelState.IsValid)
                {
                    var entity = this.GetById(model.Id) as DatabaseModelType;
                    entity.Processed  = false;
                    entity.Processing = false;

                    this.UpdateAuditInfoValues(model, entity);
                    this.BaseUpdate(model.GetEntityModel(entity));
                    this.TempData.AddInfoMessage(Resource.Successful_edit_message);
                    return(this.RedirectToAction(GlobalConstants.Index));
                }
            }

            this.ViewBag.SubmissionAction = "Update";
            return(this.View(model));
        }
Esempio n. 3
0
        public ActionResult Create()
        {
            this.ViewBag.SubmissionAction = "Create";
            var model = new ModelType();

            return(this.View(model));
        }
Esempio n. 4
0
 private void ValidateSubmissionContentLength(ModelType model, Problem problem)
 {
     if (model.Content.Length > problem.SourceCodeSizeLimit)
     {
         this.ModelState.AddModelError("Content", Resource.Submission_content_length_invalid);
     }
 }
Esempio n. 5
0
        public ActionResult Create(ModelType model)
        {
            if (model != null && this.ModelState.IsValid)
            {
                this.BaseCreate(model.GetEntityModel());
                this.TempData[GlobalConstants.InfoMessage] = SuccessfulCreationMessage;
                return(this.RedirectToAction(GlobalConstants.Index));
            }

            return(this.View(model));
        }
        public ActionResult Create(ModelType model)
        {
            if (model != null && ModelState.IsValid)
            {
                this.BaseCreate(model.GetEntityModel());
                this.TempData["InfoMessage"] = SuccessfulCreationMessage;
                return this.RedirectToAction("Index");
            }

            return this.View(model);
        }
Esempio n. 7
0
        public ActionResult Update(ModelType model)
        {
            if (model != null && this.ModelState.IsValid)
            {
                var entity = this.GetById(model.Id) as DatabaseModelType;
                this.BaseUpdate(model.GetEntityModel(entity));
                this.TempData[GlobalConstants.InfoMessage] = SuccessfulEditMessage;
                return(this.RedirectToAction(GlobalConstants.Index));
            }

            return(this.View(model));
        }
        public ActionResult Create(ModelType model)
        {
            if (model != null && ModelState.IsValid)
            {
                this.BaseCreate(new DataSourceRequest(), model.ToEntity);

                this.TempData["InfoMessage"] = SuccessfulCreationMessage;
                return this.RedirectToAction("Index");
            }

            return this.View(model);
        }
Esempio n. 9
0
        private void ValidateBinarySubmission(ModelType model, Problem problem, SubmissionType submissionType)
        {
            if (submissionType.AllowBinaryFilesUpload && !string.IsNullOrEmpty(model.ContentAsString))
            {
                this.ModelState.AddModelError("SubmissionTypeId", Resource.Wrong_submision_type);
            }

            if (submissionType.AllowedFileExtensions != null)
            {
                if (!submissionType.AllowedFileExtensionsList.Contains(model.FileExtension))
                {
                    this.ModelState.AddModelError("Content", Resource.Invalid_file_extention);
                }
            }
        }
        public ActionResult Update(ModelType model)
        {
            if (model.Id.HasValue)
            {
                if (!model.ProblemId.HasValue || !this.CheckIfUserHasProblemPermissions(model.ProblemId.Value))
                {
                    this.TempData[GlobalConstants.DangerMessage] = "Нямате привилегиите за това действие";
                    return(this.RedirectToAction("Index", "Contests", new { area = "Administration" }));
                }

                var submission = this.Data.Submissions.GetById(model.Id.Value);
                if (model.SubmissionTypeId.HasValue)
                {
                    var submissionType = this.Data.SubmissionTypes.GetById(model.SubmissionTypeId.Value);
                    if (submissionType.AllowBinaryFilesUpload && model.FileSubmission == null)
                    {
                        model.Content       = submission.Content;
                        model.FileExtension = submission.FileExtension;
                        if (this.ModelState.ContainsKey("Content"))
                        {
                            this.ModelState["Content"].Errors.Clear();
                        }
                    }
                }

                if (this.ModelState.IsValid)
                {
                    var problem = this.Data.Problems.GetById(model.ProblemId.Value);
                    if (problem != null)
                    {
                        this.ValidateParticipant(model.ParticipantId, problem.ContestId);
                    }

                    var submissionType = this.GetSubmissionType(model.SubmissionTypeId.Value);
                    if (submissionType != null)
                    {
                        this.ValidateSubmissionContentLength(model, problem);
                        this.ValidateBinarySubmission(model, problem, submissionType);
                    }

                    if (this.ModelState.IsValid)
                    {
                        if (this.IsSubmissionProcessing(submission))
                        {
                            this.TempData[GlobalConstants.DangerMessage] = Resource.Submission_is_processing;
                            return(this.RedirectToAction(nameof(this.Update), "Submissions", new { area = "Administration" }));
                        }

                        var submissionProblemId     = model.ProblemId.Value;
                        var submissionParticipantId = model.ParticipantId.Value;

                        using (var scope = new TransactionScope())
                        {
                            submission.Processed  = false;
                            submission.Processing = false;

                            this.submissionsForProcessingData.AddOrUpdateBySubmissionId(submission.Id);

                            var submissionIsBestSubmission = this.IsBestSubmission(
                                submissionProblemId,
                                submissionParticipantId,
                                submission.Id);

                            if (submissionIsBestSubmission)
                            {
                                this.participantScoresBusiness.RecalculateForParticipantByProblem(
                                    submissionParticipantId,
                                    submissionProblemId);
                            }

                            this.Data.SaveChanges();

                            this.UpdateAuditInfoValues(model, submission);
                            this.BaseUpdate(model.GetEntityModel(submission));

                            scope.Complete();
                        }

                        this.TempData.AddInfoMessage(Resource.Successful_edit_message);
                        return(this.RedirectToAction(GlobalConstants.Index));
                    }
                }
            }

            this.ViewBag.SubmissionAction = "Update";
            return(this.View(model));
        }
        public ActionResult Create(ModelType model)
        {
            if (model != null && this.ModelState.IsValid)
            {
                this.BaseCreate(model.GetEntityModel());
                this.TempData[GlobalConstants.InfoMessage] = SuccessfulCreationMessage;
                return this.RedirectToAction(GlobalConstants.Index);
            }

            return this.View(model);
        }
        public ActionResult Update(ModelType model)
        {
            if (model != null && this.ModelState.IsValid)
            {
                var entity = this.GetById(model.Id) as DatabaseModelType;
                this.BaseUpdate(model.GetEntityModel(entity));
                this.TempData[GlobalConstants.InfoMessage] = SuccessfulEditMessage;
                return this.RedirectToAction(GlobalConstants.Index);
            }

            return this.View(model);
        }