示例#1
0
        public async Task <IActionResult> Add(BenchmarkDto model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            // Manually parse input
            var testCases = InputDataParser.ReadTestCases(this.HttpContext.Request);

            // Check if benchmark code was actually entered
            if (testCases.Count() < 2)
            {
                // TODO: use correct error key
                this.ModelState.AddModelError("TestCases", "At least two test cases are required.");
                return(this.View(model));
            }

            if (testCases.Any(t => string.IsNullOrWhiteSpace(t.BenchmarkCode)))
            {
                this.ModelState.AddModelError("TestCases", "Benchmark code must not be empty.");
                return(this.View(model));
            }

            model.TestCases = new List <TestCaseDto>(testCases);

            // Check that there are no test cases with the same name
            var set = new HashSet <string>();

            foreach (var testCase in model.TestCases)
            {
                if (!set.Add(testCase.TestCaseName.ToLowerInvariant().Trim()))
                {
                    this.ModelState.AddModelError("TestCases", "Test cases must have unique names");
                    return(this.View(model));
                }
            }

            ApplicationUser user = await this.GetCurrentUserAsync();

            model.OwnerId = user?.Id;

            long id = await this.m_benchmarkRepository.Add(model);

            return(this.RedirectToAction("Show",
                                         new { Id = id, Version = 0, name = SeoFriendlyStringConverter.Convert(model.BenchmarkName) }));
        }
示例#2
0
        public async Task <IActionResult> Add(BenchmarkDto model)
        {
            await this.ValidateBenchmarkForAdd(model);

            if (this.ModelState.ErrorCount > 0)
            {
                return(View("Add", model));
            }

            ApplicationUser user = await this.GetCurrentUserAsync();

            model.OwnerId = user?.Id;

            long id = await this.m_benchmarkRepository.Add(model);

            return(this.RedirectToAction("Show",
                                         new { Id = id, Version = 0, name = SeoFriendlyStringConverter.Convert(model.BenchmarkName) }));
        }
示例#3
0
        private async Task AppendBenchmarksToSitemap(List <SitemapNode> nodes)
        {
            var benchmarks = await this.benchmarkRepository.ListAll(2000, 0).ConfigureAwait(false);

            foreach (var benchmark in benchmarks)
            {
                nodes.Add(new SitemapNode()
                {
                    LastModified = benchmark.WhenCreated,
                    Frequency    = SitemapFrequency.Never,
                    Priority     = DefaultPriority,
                    Url          = this.urlHelper.Action("Show", "Benchmarks", new { id = benchmark.Id, version = benchmark.Version, name = SeoFriendlyStringConverter.Convert(benchmark.BenchmarkName) }, this.urlHelper.ActionContext.HttpContext.Request.Scheme)
                });
            }
        }
示例#4
0
        public async Task <IActionResult> Edit(BenchmarkDto model)
        {
            ApplicationUser user = await this.GetCurrentUserAsync();

            if (user == null)
            {
                throw new NotLoggedInException("You are not logged in");
            }

            const string ViewName = "Add";

            if (!this.ModelState.IsValid)
            {
                return(this.View(ViewName, model));
            }

            // Manually parse input
            var testCases = InputDataParser.ReadTestCases(this.HttpContext.Request);

            // Check if benchmark code was actually entered
            if (testCases.Count() < 2)
            {
                this.ModelState.AddModelError("TestCases", "At least two test cases are required.");
                return(this.View(ViewName, model));
            }

            if (testCases.Any(t => string.IsNullOrWhiteSpace(t.BenchmarkCode)))
            {
                this.ModelState.AddModelError("TestCases", "Benchmark code must not be empty.");
                return(this.View(ViewName, model));
            }

            model.TestCases = new List <TestCaseDto>(testCases);

            // Check that there are no test cases with the same name
            var set = new HashSet <string>();

            foreach (var testCase in model.TestCases)
            {
                if (!set.Add(testCase.TestCaseName.ToLowerInvariant().Trim()))
                {
                    this.ModelState.AddModelError("TestCases", "Test cases must have unique names");
                    return(this.View("Add", model));
                }
            }

            try
            {
                BenchmarkDto updatedModel = await this.m_benchmarkRepository.Update(model, user.Id);

                return(this.RedirectToAction("Show", new { Id = updatedModel.Id, Version = updatedModel.Version, name = SeoFriendlyStringConverter.Convert(model.BenchmarkName) }));
            }
            catch (Exception ex)
            {
                m_logger.LogError("Can't update benchmark: " + ex.Message);
                return(RedirectToAction(ErrorActionName));
            }
        }
示例#5
0
        public async Task <IActionResult> Edit(BenchmarkDto model)
        {
            BenchmarkDto benchmark = await this.ValidateOwner(model.Id);

            ApplicationUser user = await this.GetCurrentUserAsync();

            this.ValidateInputModel(model);
            if (this.ModelState.ErrorCount > 0)
            {
                return(View("Add", model));
            }

            try
            {
                BenchmarkDto updatedModel = await this.m_benchmarkRepository.Update(model, user.Id);

                return(this.RedirectToAction("Show", new { Id = updatedModel.Id, Version = updatedModel.Version, name = SeoFriendlyStringConverter.Convert(model.BenchmarkName) }));
            }
            catch (Exception ex)
            {
                m_logger.LogError("Can't update benchmark: " + ex.Message);
                return(RedirectToAction(ErrorActionName));
            }
        }