コード例 #1
0
        public async System.Threading.Tasks.Task <ActionResult> PutAsync(ProjectSpeedy.Models.Problem.ProblemNew form, string projectId)
        {
            try
            {
                // Checks we have a valid request.
                if (form == null || !ModelState.IsValid)
                {
                    return(this.BadRequest());
                }

                // Tries to load the project to check that it exists
                var project = await this._projectService.Get(projectId);

                // Ensures we dont have a problem with the same name already
                if (project.Problems.Any(p => p.Name.Trim().ToLower() == form.Name.Trim().ToLower()))
                {
                    return(BadRequest(new ProjectSpeedy.Models.General.BadRequest()
                    {
                        Message = "There is already a problem with the same name."
                    }));
                }

                // Try and add the project.
                if (await this._problemServices.CreateAsync(projectId, form))
                {
                    return(this.Accepted());
                }

                // If we get here something has gone wrong.
                return(this.Problem());
            }
            catch (HttpRequestException e)
            {
                // Can we find the problem or project.
                if (e.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    return(NotFound());
                }

                // There has been a problem loading or saving data
                this._logger.LogError(e, e.Message);
                return(this.Problem());
            }
            catch (Exception e)
            {
                // There has been a system error.
                this._logger.LogError(e, e.Message);
                return(this.Problem());
            }
        }
コード例 #2
0
ファイル: Problem.cs プロジェクト: tmatt95/ProjectSpeedy
        /// <inheritdoc />
        public async System.Threading.Tasks.Task <bool> CreateAsync(string projectId, Models.Problem.ProblemNew form)
        {
            // The new project object
            var newProblem = new ProjectSpeedy.Models.Problem.ProblemNew()
            {
                Name            = form.Name,
                Created         = DateTime.UtcNow,
                ProjectId       = "project:" + projectId,
                Description     = form.Description,
                SuccessCriteria = form.SuccessCriteria,
            };

            // Creates the project and checks if the id is returned.
            var newId = await this._serviceBase.DocumentCreate(newProblem, Problem.PARTITION);

            return(!string.IsNullOrWhiteSpace(newId));
        }
コード例 #3
0
        public async System.Threading.Tasks.Task TestCreateInValidAsync()
        {
            // Arrange
            var mockTest       = new Mock <ProjectSpeedy.Services.IServiceBase>();
            var problemService = new ProjectSpeedy.Services.Problem(mockTest.Object);
            var form           = new ProjectSpeedy.Models.Problem.ProblemNew()
            {
                Name = "Test Problem New"
            };

            mockTest.Setup(d => d.DocumentCreate(It.IsAny <ProjectSpeedy.Models.Problem.Problem>(), "problem"))
            .Returns(Task.FromResult(""));

            // Act
            var test = await problemService.CreateAsync("ProjectId", form);

            // Assert
            Assert.AreEqual(false, test);
        }