Пример #1
0
        public ActionResult <ProjectResource> UpdateProject(int id, [FromBody] SaveProjectResource saveProjectResource)
        {
            var validator        = new SaveProjectResourceValidator();
            var validationResult = validator.Validate(saveProjectResource);

            bool requestIsInvalid = id == 0 || !validationResult.IsValid;

            if (requestIsInvalid)
            {
                return(BadRequest(validationResult.Errors));
            }

            var projectToBeUpdate = _projectService.GetProject(id);

            if (projectToBeUpdate == null)
            {
                return(NotFound());
            }

            var project = _mapper.Map <SaveProjectResource, Project>(saveProjectResource);

            project.ProjectId = id;
            _projectService.UpdateProject(project);

            var updatedProject         = _projectService.GetProject(id);
            var updatedProjectResource = _mapper.Map <Project, ProjectResource>(updatedProject);

            return(Ok(updatedProjectResource));
        }
Пример #2
0
        public ActionResult <ProjectResource> CreateProject([FromBody] SaveProjectResource saveProjectResource)
        {
            var validator        = new SaveProjectResourceValidator();
            var validationResult = validator.Validate(saveProjectResource);

            if (!validationResult.IsValid)
            {
                return(BadRequest(validationResult.Errors));
            }

            var projectToCreate = _mapper.Map <SaveProjectResource, Project>(saveProjectResource);

            _projectService.CreateProject(projectToCreate);

            var project         = _projectService.GetProject(projectToCreate.ProjectId);
            var projectResource = _mapper.Map <Project, ProjectResource>(project);

            return(Ok(projectResource));
        }