public ActionResult Create(ViewModelType model)
        {
            if (!this.IsValidContest(model))
            {
                return this.View(model);
            }

            if (model != null && this.ModelState.IsValid)
            {
                var contest = model.GetEntityModel();

                model.SubmisstionTypes.ForEach(s =>
                    {
                        if (s.IsChecked)
                        {
                            var submission = this.Data.SubmissionTypes.All().FirstOrDefault(t => t.Id == s.Id);
                            contest.SubmissionTypes.Add(submission);
                        }
                    });

                this.Data.Contests.Add(contest);
                this.Data.SaveChanges();

                TempData.Add(GlobalConstants.InfoMessage, "Състезанието беше добавено успешно");
                return this.RedirectToAction(GlobalConstants.Index);
            }

            return this.View(model);
        }
Exemple #2
0
        public ActionResult Create(ViewModelType model)
        {
            if (!this.IsValidContest(model))
            {
                return(this.View(model));
            }

            if (model != null && this.ModelState.IsValid)
            {
                var contest = model.GetEntityModel();

                model.SubmisstionTypes.ForEach(s =>
                {
                    if (s.IsChecked)
                    {
                        var submission = this.Data.SubmissionTypes.All().FirstOrDefault(t => t.Id == s.Id);
                        contest.SubmissionTypes.Add(submission);
                    }
                });

                this.Data.Contests.Add(contest);
                this.Data.SaveChanges();

                TempData.Add(GlobalConstants.InfoMessage, "Състезанието беше добавено успешно");
                return(this.RedirectToAction(GlobalConstants.Index));
            }

            return(this.View(model));
        }
        private void ValidateContest(ViewModelType model)
        {
            if (model.StartTime >= model.EndTime)
            {
                this.ModelState.AddModelError(GlobalConstants.DateTimeError, Resource.Contest_start_date_before_end);
            }

            if (model.PracticeStartTime >= model.PracticeEndTime)
            {
                this.ModelState.AddModelError(GlobalConstants.DateTimeError, Resource.Practice_start_date_before_end);
            }

            if (model.IsOnline)
            {
                if (!model.Duration.HasValue)
                {
                    this.ModelState.AddModelError(nameof(model.Duration), Resource.Required_field_for_online);
                }
                else if (model.Duration.Value.TotalHours >= 24)
                {
                    this.ModelState.AddModelError(nameof(model.Duration), Resource.Duration_invalid_format);
                }

                if (model.ProblemGroupsCount <= 0)
                {
                    this.ModelState.AddModelError(nameof(model.ProblemGroupsCount), Resource.Required_field_for_online);
                }
                else if (model.ProblemGroupsCount > ProblemGroupsCountLimit)
                {
                    this.ModelState.AddModelError(
                        nameof(model.ProblemGroupsCount),
                        string.Format(Resource.Problem_groups_count_limit, ProblemGroupsCountLimit));
                }
            }
        }
        public ActionResult Create()
        {
            var newContest = new ViewModelType();
            newContest.SubmisstionTypes = this.Data.SubmissionTypes.All().Select(SubmissionTypeViewModel.ViewModel).ToList();

            return this.View(newContest);
        }
        public ActionResult Create(ContestAdministrationViewModel model)
        {
            if (!this.IsValidContest(model))
            {
                return this.View(model);
            }

            if (model != null && this.ModelState.IsValid)
            {
                var contest = model.GetEntityModel();

                model.SubmisstionTypes.ForEach(s =>
                    {
                        if (s.IsChecked)
                        {
                            var submission = this.Data.SubmissionTypes.All().FirstOrDefault(t => t.Id == s.Id);
                            contest.SubmissionTypes.Add(submission);
                        }
                    });

                this.Data.Contests.Add(contest);
                this.Data.SaveChanges();

                this.TempData.Add(GlobalConstants.InfoMessage, Resource.Contest_added);
                return this.RedirectToAction(GlobalConstants.Index);
            }

            return this.View(model);
        }
Exemple #6
0
        public ActionResult Create()
        {
            var newContest = new ViewModelType();

            newContest.SubmisstionTypes = this.Data.SubmissionTypes.All().Select(SubmissionTypeViewModel.ViewModel).ToList();

            return(this.View(newContest));
        }
        public ActionResult Create(int?categoryId)
        {
            this.PrepareViewBagData();

            var viewModel = new ViewModelType();

            if (categoryId.HasValue)
            {
                var categoryName = this.contestCategoriesData.GetNameById(categoryId.Value);

                if (categoryName != null)
                {
                    viewModel.CategoryId   = categoryId;
                    viewModel.CategoryName = categoryName;
                }
            }

            return(this.View(viewModel));
        }
Exemple #8
0
        public static Action<SubmissionTypeViewModel> ApplySelectedTo(ContestAdministrationViewModel contest)
        {
            return st =>
            {
                var submissionViewModel = new SubmissionTypeViewModel
                {
                    Id = st.Id,
                    Name = st.Name,
                    IsChecked = false,
                };

                var selectedSubmission = contest.SelectedSubmissionTypes.FirstOrDefault(s => s.Id == st.Id);

                if (selectedSubmission != null)
                {
                    submissionViewModel.IsChecked = true;
                }

                contest.SubmissionTypes.Add(submissionViewModel);
            };
        }
Exemple #9
0
        private bool IsValidContest(ViewModelType model)
        {
            bool isValid = true;

            if (model.StartTime >= model.EndTime)
            {
                this.ModelState.AddModelError(GlobalConstants.DateTimeError, Resource.Contest_start_date_before_end);
                isValid = false;
            }

            if (model.PracticeStartTime >= model.PracticeEndTime)
            {
                this.ModelState.AddModelError(GlobalConstants.DateTimeError, Resource.Practice_start_date_before_end);
                isValid = false;
            }

            if (model.SubmissionTypes == null || !model.SubmissionTypes.Any(s => s.IsChecked))
            {
                this.ModelState.AddModelError("SelectedSubmissionTypes", Resource.Select_one_submission_type);
                isValid = false;
            }

            return(isValid);
        }
Exemple #10
0
        private bool IsValidContest(ViewModelType model)
        {
            bool isValid = true;

            if (model.StartTime >= model.EndTime)
            {
                this.ModelState.AddModelError(GlobalConstants.DateTimeError, "Началната дата на състезанието не може да бъде след крайната дата на състезанието");
                isValid = false;
            }

            if (model.PracticeStartTime >= model.PracticeEndTime)
            {
                this.ModelState.AddModelError(GlobalConstants.DateTimeError, "Началната дата за упражнения не може да бъде след крайната дата за упражнения");
                isValid = false;
            }

            if (model.SubmisstionTypes == null || !model.SubmisstionTypes.Any(s => s.IsChecked))
            {
                this.ModelState.AddModelError("SelectedSubmissionTypes", "Изберете поне един вид решение!");
                isValid = false;
            }

            return(isValid);
        }
        public ActionResult Create(ViewModelType model)
        {
            if (model.StartTime >= model.EndTime)
            {
                ModelState.AddModelError("DateTimeError", "Началната дата на състезанието не може да бъде след крайната дата на състезанието");
                return this.View(model);
            }

            if (model.PracticeStartTime >= model.PracticeEndTime)
            {
                ModelState.AddModelError("DateTimeError", "Началната дата за упражнения не може да бъде след крайната дата за упражнения");
                return this.View(model);
            }

            if (model != null && ModelState.IsValid)
            {
                var contest = model.GetEntityModel();

                model.SubmisstionTypes.ForEach(s =>
                    {
                        if (s.IsChecked)
                        {
                            var submission = this.Data.SubmissionTypes.All().FirstOrDefault(t => t.Id == s.Id);
                            contest.SubmissionTypes.Add(submission);
                        }
                    });

                this.Data.Contests.Add(contest);
                this.Data.SaveChanges();

                TempData.Add("InfoMessage", "Състезанието беше добавено успешно");
                return this.RedirectToAction("Index");
            }

            return this.View(model);
        }
Exemple #12
0
 public ActionResult Destroy([DataSourceRequest] DataSourceRequest request, ViewModelType model)
 {
     this.BaseDestroy(model.Id);
     return(this.GridOperation(request, model));
 }
 public ActionResult Destroy([DataSourceRequest]DataSourceRequest request, ViewModelType model)
 {
     this.BaseDestroy(model.Id);
     return this.GridOperation(request, model);
 }
 public ActionResult Destroy([DataSourceRequest]DataSourceRequest request, ModelType model)
 {
     return this.BaseDestroy(request, model.ToEntity);
 }
        private bool IsValidContest(ViewModelType model)
        {
            bool isValid = true;

            if (model.StartTime >= model.EndTime)
            {
                this.ModelState.AddModelError(GlobalConstants.DateTimeError, "Началната дата на състезанието не може да бъде след крайната дата на състезанието");
                isValid = false;
            }

            if (model.PracticeStartTime >= model.PracticeEndTime)
            {
                this.ModelState.AddModelError(GlobalConstants.DateTimeError, "Началната дата за упражнения не може да бъде след крайната дата за упражнения");
                isValid = false;
            }

            if (model.SubmisstionTypes == null || !model.SubmisstionTypes.Any(s => s.IsChecked))
            {
                this.ModelState.AddModelError("SelectedSubmissionTypes", "Изберете поне един вид решение!");
                isValid = false;
            }

            return isValid;
        }
 public ActionResult Destroy([DataSourceRequest]DataSourceRequest request, ContestAdministrationViewModel model)
 {
     this.BaseDestroy(model.Id);
     return this.GridOperation(request, model);
 }
        public ActionResult Edit(ContestAdministrationViewModel model)
        {
            if (!this.IsValidContest(model))
            {
                return this.View(model);
            }

            if (model != null && this.ModelState.IsValid)
            {
                var contest = this.Data.Contests.All().FirstOrDefault(c => c.Id == model.Id);

                if (contest == null)
                {
                    this.TempData.Add(GlobalConstants.DangerMessage, "Състезанието не е намерено");
                    return this.RedirectToAction(GlobalConstants.Index);
                }

                contest = model.GetEntityModel(contest);
                contest.SubmissionTypes.Clear();

                model.SubmisstionTypes.ForEach(s =>
                {
                    if (s.IsChecked)
                    {
                        var submission = this.Data.SubmissionTypes.All().FirstOrDefault(t => t.Id == s.Id);
                        contest.SubmissionTypes.Add(submission);
                    }
                });

                this.Data.Contests.Update(contest);
                this.Data.SaveChanges();

                this.TempData.Add(GlobalConstants.InfoMessage, "Състезанието беше променено успешно");
                return this.RedirectToAction(GlobalConstants.Index);
            }

            return this.View(model);
        }
        private bool IsValidContest(ContestAdministrationViewModel model)
        {
            bool isValid = true;

            if (model.StartTime >= model.EndTime)
            {
                this.ModelState.AddModelError(GlobalConstants.DateTimeError, Resource.Contest_start_date_before_end);
                isValid = false;
            }

            if (model.PracticeStartTime >= model.PracticeEndTime)
            {
                this.ModelState.AddModelError(GlobalConstants.DateTimeError, Resource.Practice_start_date_before_end);
                isValid = false;
            }

            if (model.SubmisstionTypes == null || !model.SubmisstionTypes.Any(s => s.IsChecked))
            {
                this.ModelState.AddModelError("SelectedSubmissionTypes", Resource.Select_one_submission_type);
                isValid = false;
            }

            return isValid;
        }