public IHttpActionResult PutServiceDescription(int id, ServiceDescription_ApiRequestUpdateModel serviceDescriptionRequestModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != serviceDescriptionRequestModel.Id)
            {
                return(BadRequest());
            }

            var serviceDescription = _mapper.Map <ServiceDescription>(serviceDescriptionRequestModel);

            var count = _serviceDescriptionService.Update(serviceDescription);

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

            return(Ok(serviceDescriptionResponseModel));
        }
Exemplo n.º 2
0
        public ActionResult Edit(int idServiceDescription, ServiceDescription_MvcViewModel serviceDescriptionViewModel)
        {
            var serviceDescription = _serviceDescriptionService.Get(idServiceDescription);

            if (serviceDescription != null)
            {
                if (serviceDescription.IdOwnerUser != IdUser)
                {
                    AddToastDangerMessage(WebResource.UserIsNotTheOwner);
                    return(View());
                }
            }
            else
            {
                AddToastWarningMessage(WebResource.AnErrorHasOccuredServiceDescriptionNotFoundInDatabase);

                return(View());
            }

            try
            {
                serviceDescription.ServiceName = serviceDescriptionViewModel.ServiceName;
                serviceDescription.Xml         = serviceDescriptionViewModel.Xml;

                _serviceDescriptionService.Update(serviceDescription);

                AddToastSuccessMessage(WebResource.ServiceDescriptionUpdateSuccess);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                AddToastDangerMessage(WebResource.ServiceDescriptionUpdateFail);

                return(View());
            }
        }
Exemplo n.º 3
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));
        }