Beispiel #1
0
        public IHttpActionResult PutIssue(int id, Issue_ApiRequestUpdateModel issueRequestUpdateModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id <= 0)
            {
                return(BadRequest("Invalid Id."));
            }

            var existingIssue = _issueService.Get(id);

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

            var idUser = _userIdentityService.Id;

            if (existingIssue.IdOwnerUser != idUser)
            {
                return(Unauthorized());
            }

            var issue = _mapper.Map <Issue>(issueRequestUpdateModel);

            issue.Id = id;

            var count = _issueService.Update(issue);

            var issueResponseModel = _mapper.Map <Issue_ApiResponseViewModel>(issue);

            var serviceDescription = _serviceDescriptionService.Get(issueResponseModel.IdServiceDescription);

            var graphDataObject = JsonConvert.DeserializeObject <CytoscapeObject>(serviceDescription.GraphJson);

            //TODO: extract IFs-ELSEs below to private methods
            if (issueResponseModel.IdWsdlInterface.HasValue)
            {
                var wsdlInterface = _serviceDescriptionService.GetWsdlInterfaceWithSemanticAnnotations(issueResponseModel.IdWsdlInterface.Value);

                var allIssuesSolved = !wsdlInterface.Issues.Any(x => !x.Solved);

                if (allIssuesSolved)
                {
                    graphDataObject = _graphService.RemoveIssueFromWsdlInterface(graphDataObject, wsdlInterface) as CytoscapeObject;
                }
                else
                {
                    graphDataObject = _graphService.AddIssueToWsdlInterface(graphDataObject, wsdlInterface) as CytoscapeObject;
                }
            }
            else if (issueResponseModel.IdWsdlOperation.HasValue)
            {
                var wsdlOperation = _serviceDescriptionService.GetWsdlOperationWithSemanticAnnotations(issueResponseModel.IdWsdlOperation.Value);

                var allIssuesSolved = !wsdlOperation.Issues.Any(x => !x.Solved);

                if (allIssuesSolved)
                {
                    graphDataObject = _graphService.RemoveIssueFromWsdlOperation(graphDataObject, wsdlOperation) as CytoscapeObject;
                }
                else
                {
                    graphDataObject = _graphService.AddIssueToWsdlOperation(graphDataObject, wsdlOperation) as CytoscapeObject;
                }
            }
            else if (issueResponseModel.IdXsdComplexType.HasValue)
            {
                var xsdComplexElement = _serviceDescriptionService.GetXsdComplexTypeWithSemanticAnnotations(issueResponseModel.IdXsdComplexType.Value);

                var allIssuesSolved = !xsdComplexElement.Issues.Any(x => !x.Solved);

                if (allIssuesSolved)
                {
                    graphDataObject = _graphService.RemoveIssueFromXsdComplexType(graphDataObject, xsdComplexElement) as CytoscapeObject;
                }
                else
                {
                    graphDataObject = _graphService.AddIssueToXsdComplexType(graphDataObject, xsdComplexElement) as CytoscapeObject;
                }
            }
            else if (issueResponseModel.IdXsdSimpleType.HasValue)
            {
                var xsdSimpleElement = _serviceDescriptionService.GetXsdSimpleTypeWithSemanticAnnotations(issueResponseModel.IdXsdSimpleType.Value);

                var allIssuesSolved = !xsdSimpleElement.Issues.Any(x => !x.Solved);

                if (allIssuesSolved)
                {
                    graphDataObject = _graphService.RemoveIssueFromXsdSimpleType(graphDataObject, xsdSimpleElement) as CytoscapeObject;
                }
                else
                {
                    graphDataObject = _graphService.AddIssueToXsdSimpleType(graphDataObject, xsdSimpleElement) as CytoscapeObject;
                }
            }

            serviceDescription.GraphJson = JsonConvert.SerializeObject(graphDataObject);

            _serviceDescriptionService.Update(serviceDescription);

            var serviceDescriptionResponseModel = _mapper.Map <ServiceDescription_ApiResponseViewModel>(serviceDescription);

            issueResponseModel.ServiceDescription = serviceDescriptionResponseModel;

            return(Ok(issueResponseModel));
        }