public async Task <IEnumerable <PublishedDocumentVM> > GetPublishedDocumentListWithStatusAsync(string projectID, string user) { //ProjectMasterVM project = new ProjectMasterVM(); using (var client = new HttpClient()) { client.BaseAddress = new Uri(_configuration.IATIWebServiceUrl); // We should store this in the web.config file client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // This probably removes the need to have the config in the API try { // HTTP GET HttpResponseMessage response = await client.GetAsync("PublishedDocument/GetPublishedDocumentByProjectId/" + projectID);// This URI shouldbe in the web.config file or passed via the AMP Service Layer. if (response.IsSuccessStatusCode) { List <PublishedDocumentVM> publishedDocumentVM = new List <PublishedDocumentVM>(); var publishedDoc = Newtonsoft.Json.JsonConvert.DeserializeObject <IEnumerable <PublishedDocumentVM> >(response.Content.ReadAsStringAsync().Result); foreach (var projectDoc in publishedDoc) { publishedDocumentVM.Add(projectDoc); } return(publishedDocumentVM); } else { Exception ex = new Exception(response.StatusCode + " - " + response.ReasonPhrase); // Executes the error engine (ProjectID is optional, exception) errorengine.LogError(ex, user); throw ex; } } catch (Exception ex) { // Executes the error engine (ProjectID is optional, exception) errorengine.LogError(projectID, ex, user); throw ex; } } }
public async Task <bool> StartWorkflow(WorkflowVM workflowvm, string user) { try { VMToWorkflowMasterMapper workflowMapper = new VMToWorkflowMasterMapper(); WorkflowMaster request = workflowMapper.MapVMToWorkflowMaster(workflowvm.WorkflowRequest); RequestBuilder builder = new RequestBuilder(request, _ampRepository, user); builder.BuildWorkflowMaster(); if (workflowvm.DocumentID != null) { WorkflowDocumentBuilder documentBuilder = new WorkflowDocumentBuilder(workflowvm.DocumentID, workflowvm.DocumentDescription, builder.workflow.WorkFlowID, user); documentBuilder.Build(); _ampRepository.InsertWorkflowDocument(documentBuilder.Document); } _ampRepository.InsertWorkFlowMaster(builder.workflow); _ampRepository.Save(); // need to handle planned end date - the planned end date table row for the project // is inserted befre workflow task is created. Now the workflow is created // and being sennt for approval we need to update the newly created row for the project // in the planned end date table with the workflowTaskID if (workflowvm.WorkflowRequest.TaskID == Constants.PlannedEndDate) { ProjectPlannedEndDate projectPlannedEndToUpdate = _ampRepository.GetProjectPlannedEndDate(request.ProjectID); projectPlannedEndToUpdate.WorkTaskID = request.WorkFlowID; _ampRepository.UpdatePlannedEndDate(projectPlannedEndToUpdate); _ampRepository.Save(); } return(true); } catch (Exception exception) { _errorengine.LogError(workflowvm.WorkflowResponse.ProjectID, exception, user); return(false); } }