public string GetType(string type) { Uri typesUri = new Uri(string.Format("{0}/LookUp/{1}/{2}/{3}/commtypes?UserId={4}", Url, Context, Version, ContractNumber, HeaderUserId)); HttpClient typesClient = GetHttpClient(typesUri); GetAllCommTypesDataRequest typesRequest = new GetAllCommTypesDataRequest { Version = Version, Context = Context, ContractNumber = ContractNumber }; DataContractJsonSerializer typesJsonSer = new DataContractJsonSerializer(typeof(GetAllCommTypesDataRequest)); MemoryStream typesMs = new MemoryStream(); typesJsonSer.WriteObject(typesMs, typesRequest); typesMs.Position = 0; //use a Stream reader to construct the StringContent (Json) StreamReader typesSr = new StreamReader(typesMs); StringContent typesContent = new StringContent(typesSr.ReadToEnd(), System.Text.Encoding.UTF8, "application/json"); typesMs.Dispose(); //Post the data var typesResponse = typesClient.GetStringAsync(typesUri); var typesResponseContent = typesResponse.Result; string typesResponseString = typesResponseContent; GetAllCommTypesDataResponse responseTypes = null; using (var typesMsResponse = new MemoryStream(Encoding.Unicode.GetBytes(typesResponseString))) { var typesSerializer = new DataContractJsonSerializer(typeof(GetAllCommTypesDataResponse)); responseTypes = (GetAllCommTypesDataResponse)typesSerializer.ReadObject(typesMsResponse); } typesLookUp = responseTypes.CommTypes; string t = ""; foreach (CommTypeData c in typesLookUp) { if (String.Compare(type, c.Name, true) == 0) { t = c.Id; } } return(t); }
public GetAllCommTypesDataResponse GetAllCommTypes(GetAllCommTypesDataRequest request) { GetAllCommTypesDataResponse response = new GetAllCommTypesDataResponse(); ILookUpRepository repo = Factory.GetRepository(request, RepositoryType.LookUp); List <CommTypeData> data = repo.GetAllCommTypes(); if (data != null) { response.CommTypes = data; } return(response); }
public void GetAllCommTypes_Test() { // Arrange double version = 1.0; string contractNumber = "InHealth001"; string context = "NG"; GetAllCommTypesDataRequest request = new GetAllCommTypesDataRequest { Context = context, ContractNumber = contractNumber, Version = version }; // Act LookUpDataManager lm = new LookUpDataManager { Factory = new LookUpRepositoryFactory() }; GetAllCommTypesDataResponse response = lm.GetAllCommTypes(request); // Assert Assert.AreNotEqual(0, response.CommTypes.Count); }
public GetAllCommTypesDataResponse Get(GetAllCommTypesDataRequest request) { GetAllCommTypesDataResponse response = new GetAllCommTypesDataResponse(); try { if (string.IsNullOrEmpty(request.UserId)) { throw new UnauthorizedAccessException("LookUpDD:Get()::Unauthorized Access"); } response = LookUpDataManager.GetAllCommTypes(request); response.Version = request.Version; } catch (Exception ex) { CommonFormatter.FormatExceptionResponse(response, base.Response, ex); string aseProcessID = ConfigurationManager.AppSettings.Get("ASEProcessID") ?? "0"; Common.Helper.LogException(int.Parse(aseProcessID), ex); } return(response); }