Example #1
0
        public GetTimeZoneDataResponse GetDefaultTimeZone(GetTimeZoneDataRequest request)
        {
            GetTimeZoneDataResponse response = new GetTimeZoneDataResponse();
            ILookUpRepository       repo     = Factory.GetRepository(request, RepositoryType.LookUp);
            TimeZoneData            data     = repo.GetDefaultTimeZone();

            if (data != null)
            {
                response.TimeZone = data;
            }
            return(response);
        }
Example #2
0
        public TimeZoneData GetDefaultTimeZone()
        {
            Uri zoneUri = new Uri(string.Format("{0}/LookUp/{1}/{2}/{3}/TimeZone/Default?UserId={4}",
                                                Url,
                                                Context,
                                                Version,
                                                ContractNumber,
                                                HeaderUserId));
            HttpClient zoneClient = GetHttpClient(zoneUri);

            GetTimeZoneDataRequest zoneRequest = new GetTimeZoneDataRequest
            {
                Version        = Version,
                Context        = Context,
                ContractNumber = ContractNumber
            };

            DataContractJsonSerializer zoneJsonSer = new DataContractJsonSerializer(typeof(GetTimeZoneDataRequest));
            MemoryStream zoneMs = new MemoryStream();

            zoneJsonSer.WriteObject(zoneMs, zoneRequest);
            zoneMs.Position = 0;

            //use a Stream reader to construct the StringContent (Json)
            StreamReader  zoneSr      = new StreamReader(zoneMs);
            StringContent zoneContent = new StringContent(zoneSr.ReadToEnd(), System.Text.Encoding.UTF8, "application/json");

            zoneMs.Dispose();

            //Post the data
            var zoneResponse        = zoneClient.GetStringAsync(zoneUri);
            var zoneResponseContent = zoneResponse.Result;

            string zoneResponseString            = zoneResponseContent;
            GetTimeZoneDataResponse responseZone = null;

            using (var zoneMsResponse = new MemoryStream(Encoding.Unicode.GetBytes(zoneResponseString)))
            {
                var zoneSerializer = new DataContractJsonSerializer(typeof(GetTimeZoneDataResponse));
                responseZone = (GetTimeZoneDataResponse)zoneSerializer.ReadObject(zoneMsResponse);
            }
            return(responseZone.TimeZone);
        }
Example #3
0
        public void GetDefaultTimeZone_Test()
        {
            // Arrange
            double version                 = 1.0;
            string contractNumber          = "InHealth001";
            string context                 = "NG";
            GetTimeZoneDataRequest request = new GetTimeZoneDataRequest {
                Context = context, ContractNumber = contractNumber, Version = version
            };

            // Act
            LookUpDataManager lm = new LookUpDataManager {
                Factory = new LookUpRepositoryFactory()
            };
            GetTimeZoneDataResponse response = lm.GetDefaultTimeZone(request);

            // Assert
            Assert.AreEqual("Central", response.TimeZone.Name);
        }
Example #4
0
        public GetTimeZoneDataResponse Get(GetTimeZoneDataRequest request)
        {
            GetTimeZoneDataResponse response = new GetTimeZoneDataResponse();

            try
            {
                if (string.IsNullOrEmpty(request.UserId))
                {
                    throw new UnauthorizedAccessException("LookUpDD:Get()::Unauthorized Access");
                }

                response         = LookUpDataManager.GetDefaultTimeZone(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);
        }