Esempio n. 1
0
        public IActionResult PostNewProjectPhase(NewProjectPhaseDto newPhase, [FromRoute] string orgId)
        {
            try
            {
                _unitOfWorkManager.StartUnitOfWork();
                ProjectPhase phase = _projectManager.AddProjectPhase(
                    newPhase.Title,
                    newPhase.Description,
                    newPhase.StartDate,
                    newPhase.EndDate,
                    newPhase.ProjectId);
                _unitOfWorkManager.EndUnitOfWork();

                return(CreatedAtAction(
                           "GetProjectPhase",
                           new { orgId, id = phase.ProjectPhaseId },
                           _mapper.Map <ProjectPhaseDto>(phase)));
            }
            catch (ValidationException ve)
            {
                return(UnprocessableEntity($"Invalid input data: {ve.ValidationResult.ErrorMessage}"));
            }
            catch (Exception e)
            {
                return(BadRequest($"Something went wrong in creating the project phase: {e.Message}."));
            }
        }
Esempio n. 2
0
        public IActionResult UpdateProjectPhase(int id, NewProjectPhaseDto updatedValues)
        {
            try
            {
                _unitOfWorkManager.StartUnitOfWork();
                ProjectPhase updatedPhase = _projectManager.ChangeProjectPhase(
                    id,
                    updatedValues.Title,
                    updatedValues.Description,
                    updatedValues.StartDate,
                    updatedValues.EndDate,
                    updatedValues.ProjectId);
                _unitOfWorkManager.EndUnitOfWork();

                if (updatedPhase == null)
                {
                    return(BadRequest("Something went wrong while updating the project phase."));
                }

                return(Ok(_mapper.Map <ProjectPhaseDto>(updatedPhase)));
            }
            catch (ValidationException ve)
            {
                return(UnprocessableEntity($"Invalid input data: {ve.ValidationResult.ErrorMessage}"));
            }
            catch (ArgumentException e)
            {
                switch (e.ParamName)
                {
                case "id":
                    return(NotFound(e.Message));

                case "projectId":
                    return(UnprocessableEntity(e.Message));

                default:
                    return(BadRequest(e.Message));
                }
            }
        }