public Dtos.GetServiceTypeOutput GetServiceTypes(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 = _serviceTypeRepository.GetAll();

            //Used AutoMapper to automatically convert List<Task> to List<TaskDto>.
            //We must declare mappings to be able to use AutoMapper

            List<Dtos.ServiceTypeDto> serviceTypes = new List<Dtos.ServiceTypeDto>();

            serviceTypes = new Dtos.GetServiceTypeOutput
                         {
                             ServiceTypes = Mapper.Map<List<Dtos.ServiceTypeDto>>(types)
                         }.ServiceTypes;

            var query = (from cv in criteriaOutput.CriteriaValues
                         from st in serviceTypes
                         where st.Description == cv.Name
                         select new Dtos.ServiceTypeDto
                         {
                             Code = st.Code,
                             CreationTime = st.CreationTime,
                             CreatorUserId = st.CreatorUserId,
                             Description = st.Description,
                             LastModificationTime = st.LastModificationTime,
                             LastModifierUserId = st.LastModifierUserId,
                             Id = cv.Id,
                             CreditCount = cv.CreditCount,
                             CriteriaRefId = cv.CriteriaRefId,
                             Name = cv.Name
                         }).ToList<Dtos.ServiceTypeDto>();

            return new Dtos.GetServiceTypeOutput() { ServiceTypes = query };
            
        }
예제 #2
0
        public Dtos.GetServiceTypeOutput GetServiceTypes(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 = _serviceTypeRepository.GetAll();

            //Used AutoMapper to automatically convert List<Task> to List<TaskDto>.
            //We must declare mappings to be able to use AutoMapper

            List <Dtos.ServiceTypeDto> serviceTypes = new List <Dtos.ServiceTypeDto>();

            serviceTypes = new Dtos.GetServiceTypeOutput
            {
                ServiceTypes = Mapper.Map <List <Dtos.ServiceTypeDto> >(types)
            }.ServiceTypes;

            var query = (from cv in criteriaOutput.CriteriaValues
                         from st in serviceTypes
                         where st.Description == cv.Name
                         select new Dtos.ServiceTypeDto
            {
                Code = st.Code,
                CreationTime = st.CreationTime,
                CreatorUserId = st.CreatorUserId,
                Description = st.Description,
                LastModificationTime = st.LastModificationTime,
                LastModifierUserId = st.LastModifierUserId,
                Id = cv.Id,
                CreditCount = cv.CreditCount,
                CriteriaRefId = cv.CriteriaRefId,
                Name = cv.Name
            }).ToList <Dtos.ServiceTypeDto>();

            return(new Dtos.GetServiceTypeOutput()
            {
                ServiceTypes = query
            });
        }