Exemple #1
0
        public async Task <IActionResult> Index(TestsInputModel input)
        {
            if (input.CandidateType < 0)// throw error from controller
            {
                this.ModelState.AddModelError(nameof(TestsInputModel.CandidateType), "Custom Error Message");
            }

            if (!this.ModelState.IsValid)
            {
                input.AllCandidateTypes = this.positionService.GetAll();
                return(this.View(input));//populate data in forms after error
            }

            using (var fileStream = new FileStream(@"C:\Temp\User.pdf", FileMode.Create))
            {
                var expectedFileExt = new[] { ".pdf", ".doc", ".docx" };

                if (expectedFileExt.Any(x => input.CV.First().FileName.EndsWith(x)))
                {
                    if (input.CV.First().Length > 1024 * 1024 * 10)//check the file size
                    {
                        this.ModelState.AddModelError(nameof(TestsInputModel.CV), "фаила е по гола м от 10 мб.");
                    }
                    await input.CV.First().CopyToAsync(fileStream);
                }
            }

            return(this.Redirect("/"));
        }
Exemple #2
0
        public IActionResult Index()
        {
            var model = new TestsInputModel()
            {
                University = "SoftUni",                           //defaul value

                AllCandidateTypes = this.positionService.GetAll() // Get enum from DB
            };

            return(this.View(model));
        }
        private string GetTestCodeClassName(TestsInputModel testsInput)
        {
            var taskSkeleton = testsInput.TaskSkeletonAsString ?? string.Empty;

            var className = Regex.Match(taskSkeleton, this.classNameInSkeletonRegexPattern)
                            .Groups[1]
                            .Value;

            if (string.IsNullOrWhiteSpace(className))
            {
                throw new ArgumentException(this.classNameNotFoundErrorMessage);
            }

            return(className);
        }