public IHttpActionResult CreateUpdateRequirement([FromUri] int projectId, [FromBody] UpdateRequirementsCommand command)
        {
            if (command == null || projectId <= 0)
            {
                return(BadRequest(DefaultMessages.InvalidBody));
            }
            List <UpdateRequirementsCommand> commands = new List <UpdateRequirementsCommand>()
            {
                command
            };
            ValidationError error = new UpdateRequirementsCommandValidator().Validate(commands);

            if (error.IsInvalid)
            {
                return(BadRequest(error.Error));
            }
            ProjectsRepository projectsRepository = new ProjectsRepository(Connection, HttpContext.Current.User);

            if (projectsRepository.Find(projectId) == null)
            {
                return(BadRequest("Projeto não encontrado."));
            }
            List <Requirement>     requirements = new RequirementsService().MapCommand(commands);
            RequirementsRepository repository   = new RequirementsRepository(Connection);

            repository.Update(projectId, requirements);
            return(Ok());
        }
        public void ShouldGetAnAverageOf72()
        {
            // Arrange
            RequirementsService service = new RequirementsService();
            Student             student = Repository.GetStudent(2);

            // Act
            int result = service.GetStudentAverage(student);

            // Assert
            Assert.AreEqual(72, result);
        }
        public void ShouldNotHaveEnoughCredits()
        {
            // Arrange
            RequirementsService service = new RequirementsService();
            Diploma             diploma = Repository.GetDiploma(1);
            Student             student = Repository.GetStudent(2);

            // Act
            bool result = service.CreditsFulfilled(diploma.Requirements[0], student);

            // Assert
            Assert.IsFalse(result);
        }
        public void Create(int projectId, List <CreateRequirementsCommand> command)
        {
            List <Requirement> requirements = new RequirementsService().MapCommand(command, FindNextId(projectId));

            foreach (Requirement requirement in requirements)
            {
                Create(projectId, requirement);
                if (requirement.Children != null)
                {
                    foreach (Requirement childRequirement in requirement.Children)
                    {
                        Create(projectId, childRequirement);
                    }
                }
            }
        }