Example #1
0
        public ActionResult Create(
            [DataSourceRequest] DataSourceRequest request,
            ViewModelType model)
        {
            if (!this.IsModelAndContestValid(model))
            {
                return(this.GridOperation(request, model));
            }

            if (!this.contestsData.IsOnlineById(model.ContestId))
            {
                this.ModelState.AddModelError(
                    string.Empty,
                    string.Format(Resource.Can_create_only_in_online_contest, nameof(ContestType.OnlinePracticalExam)));

                return(this.GridOperation(request, model));
            }

            if (this.contestsData.IsActiveById(model.ContestId))
            {
                this.ModelState.AddModelError(string.Empty, Resource.Active_contest_cannot_add_problem_group);
                return(this.GridOperation(request, model));
            }

            var problemGroup = model.GetEntityModel();

            problemGroup.Type = model.Type.GetValidTypeOrNull();

            model.Id = (int)this.BaseCreate(problemGroup);
            return(this.GridOperation(request, model));
        }
Example #2
0
        public ActionResult Update([DataSourceRequest] DataSourceRequest request, ViewModelType model)
        {
            var existingProblemGroup = this.GetByIdAsNoTracking(model.Id);

            if (existingProblemGroup == null || !this.IsModelAndContestValid(model))
            {
                return(this.GridOperation(request, model));
            }

            if (existingProblemGroup.OrderBy != model.OrderBy &&
                !this.contestsData.IsOnlineById(model.ContestId))
            {
                this.ModelState.AddModelError(
                    string.Empty,
                    string.Format(
                        Resource.Can_edit_orderby_only_in_online_contest,
                        ContestType.OnlinePracticalExam.GetDescription()));

                return(this.GridOperation(request, model));
            }

            var newProblemGroup = model.GetEntityModel(existingProblemGroup);

            newProblemGroup.Type = model.Type.GetValidTypeOrNull();

            this.BaseUpdate(newProblemGroup);
            return(this.GridOperation(request, model));
        }