public Dtos.GetQuoteTypeOutput GetQuoteTypes(CreditsHero.Common.Dtos.GetCriteriaInput input) { #region CreditsHero CriteriaValues var creditsHeroFormat = String.Format("{0}api/services/app/Criteria/GetCriteriaValues", System.Configuration.ConfigurationSettings.AppSettings["creditsHero:WebServiceApiPrefix"]); //var creditsHeroFormat = "http://creditshero.azurewebsites.net/api/services/cd/Criteria/GetCriteriaValues"; //var creditsHeroFormat = "http://localhost:6234/api/services/cd/Criteria/GetCriteriaValues"; var timelineUrl = string.Format(creditsHeroFormat); CreditsHero.Common.Dtos.GetCriteriaValuesOutput criteriaOutput = new CreditsHero.Common.Dtos.GetCriteriaValuesOutput(); //Serialize object to JSON MemoryStream jsonStream = new MemoryStream(); CreditsHero.Common.Dtos.GetCriteriaInput criteriaInput = new CreditsHero.Common.Dtos.GetCriteriaInput() { CompanyId = input.CompanyId, CriteriaId = input.CriteriaId }; string jsonData = Newtonsoft.Json.JsonConvert.SerializeObject(criteriaInput); byte[] byteArray = Encoding.UTF8.GetBytes(jsonData); HttpWebRequest creditsHeroRequest = (HttpWebRequest)WebRequest.Create(timelineUrl); creditsHeroRequest.ContentType = "application/json;charset=utf-8"; creditsHeroRequest.ContentLength = byteArray.Length; creditsHeroRequest.Method = "POST"; Stream newStream = creditsHeroRequest.GetRequestStream(); newStream.Write(byteArray, 0, byteArray.Length); newStream.Close(); WebResponse timeLineResponse = creditsHeroRequest.GetResponse(); using (timeLineResponse) { using (var reader = new StreamReader(timeLineResponse.GetResponseStream())) { var results = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(reader.ReadToEnd()); criteriaOutput.CriteriaValues = new List <CreditsHero.Common.Dtos.CriteriaValuesDto>(); foreach (var item in results.result.criteriaValues) { criteriaOutput.CriteriaValues.Add( Newtonsoft.Json.JsonConvert.DeserializeObject <CreditsHero.Common.Dtos.CriteriaValuesDto>(item.ToString())); } } } #endregion //Called specific GetAllWithPeople method of task repository. var types = _quoteTypeRepository.GetAll(); //Used AutoMapper to automatically convert List<Task> to List<TaskDto>. //We must declare mappings to be able to use AutoMapper List <Dtos.QuoteTypeDto> quoteTypes = new List <Dtos.QuoteTypeDto>(); quoteTypes = new Dtos.GetQuoteTypeOutput { QuoteTypes = Mapper.Map <List <Dtos.QuoteTypeDto> >(types) }.QuoteTypes; var query = (from cv in criteriaOutput.CriteriaValues from qt in quoteTypes where qt.DisplayName == cv.Name select new Dtos.QuoteTypeDto { Quote = qt.Quote, CreationTime = qt.CreationTime, CreatorUserId = qt.CreatorUserId, DisplayName = qt.DisplayName, LastModificationTime = qt.LastModificationTime, LastModifierUserId = qt.LastModifierUserId, Id = cv.Id, CreditCount = cv.CreditCount, CriteriaRefId = cv.CriteriaRefId, Name = cv.Name }).ToList <Dtos.QuoteTypeDto>(); return(new Dtos.GetQuoteTypeOutput() { QuoteTypes = query }); }
public Dtos.GetQuoteTypeOutput GetQuoteTypes(CreditsHero.Common.Dtos.GetCriteriaInput input) { #region CreditsHero CriteriaValues var creditsHeroFormat = String.Format("{0}api/services/app/Criteria/GetCriteriaValues", System.Configuration.ConfigurationSettings.AppSettings["creditsHero:WebServiceApiPrefix"]); //var creditsHeroFormat = "http://creditshero.azurewebsites.net/api/services/cd/Criteria/GetCriteriaValues"; //var creditsHeroFormat = "http://localhost:6234/api/services/cd/Criteria/GetCriteriaValues"; var timelineUrl = string.Format(creditsHeroFormat); CreditsHero.Common.Dtos.GetCriteriaValuesOutput criteriaOutput = new CreditsHero.Common.Dtos.GetCriteriaValuesOutput(); //Serialize object to JSON MemoryStream jsonStream = new MemoryStream(); CreditsHero.Common.Dtos.GetCriteriaInput criteriaInput = new CreditsHero.Common.Dtos.GetCriteriaInput() { CompanyId = input.CompanyId, CriteriaId = input.CriteriaId }; string jsonData = Newtonsoft.Json.JsonConvert.SerializeObject(criteriaInput); byte[] byteArray = Encoding.UTF8.GetBytes(jsonData); HttpWebRequest creditsHeroRequest = (HttpWebRequest)WebRequest.Create(timelineUrl); creditsHeroRequest.ContentType = "application/json;charset=utf-8"; creditsHeroRequest.ContentLength = byteArray.Length; creditsHeroRequest.Method = "POST"; Stream newStream = creditsHeroRequest.GetRequestStream(); newStream.Write(byteArray, 0, byteArray.Length); newStream.Close(); WebResponse timeLineResponse = creditsHeroRequest.GetResponse(); using (timeLineResponse) { using (var reader = new StreamReader(timeLineResponse.GetResponseStream())) { var results = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(reader.ReadToEnd()); criteriaOutput.CriteriaValues = new List<CreditsHero.Common.Dtos.CriteriaValuesDto>(); foreach (var item in results.result.criteriaValues) { criteriaOutput.CriteriaValues.Add( Newtonsoft.Json.JsonConvert.DeserializeObject<CreditsHero.Common.Dtos.CriteriaValuesDto>(item.ToString())); } } } #endregion //Called specific GetAllWithPeople method of task repository. var types = _quoteTypeRepository.GetAll(); //Used AutoMapper to automatically convert List<Task> to List<TaskDto>. //We must declare mappings to be able to use AutoMapper List<Dtos.QuoteTypeDto> quoteTypes = new List<Dtos.QuoteTypeDto>(); quoteTypes = new Dtos.GetQuoteTypeOutput { QuoteTypes = Mapper.Map<List<Dtos.QuoteTypeDto>>(types) }.QuoteTypes; var query = (from cv in criteriaOutput.CriteriaValues from qt in quoteTypes where qt.DisplayName == cv.Name select new Dtos.QuoteTypeDto { Quote = qt.Quote, CreationTime = qt.CreationTime, CreatorUserId = qt.CreatorUserId, DisplayName = qt.DisplayName, LastModificationTime = qt.LastModificationTime, LastModifierUserId = qt.LastModifierUserId, Id = cv.Id, CreditCount = cv.CreditCount, CriteriaRefId = cv.CriteriaRefId, Name = cv.Name }).ToList<Dtos.QuoteTypeDto>(); return new Dtos.GetQuoteTypeOutput() { QuoteTypes = query }; }