public async Task<Dtos.GetCriteriaValuesOutput> GetCriteriaValues(Dtos.GetCriteriaInput input)
        {
            try
            {
                List<CriteriaValues> criteriaValues = new List<CriteriaValues>();
                //Called specific GetAllWithPeople method of task repository.
                if ((input.CompanyId.HasValue && input.CompanyId.HasValue) && (input.CriteriaId.HasValue && input.CriteriaId > 0))
                    criteriaValues = _criteriaValuesRepository.GetAllCriteriaValues(input.CompanyId.Value, input.CriteriaId.Value);
                else
                    criteriaValues = _criteriaValuesRepository.GetAllCriteriaValues(input.CompanyId.Value);


                var results = new Dtos.GetCriteriaValuesOutput
                {
                    CriteriaValues = Mapper.Map<List<Dtos.CriteriaValuesDto>>(criteriaValues)
                };

                return results;
            }
            catch(System.Exception exc)
            {
                throw exc;
            }
        }
        /// <summary>
        /// Gets list of Cities
        /// </summary>
        /// <returns></returns>
        public Dtos.GetLocationOutput GetCities(CreditsHero.Common.Dtos.GetCriteriaInput input, string state)
        {
            if (state != String.Empty)
            {
                #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

                var cities = _locationRepository.GetCities(state);

                List<Dtos.LocationDto> locations = new List<Dtos.LocationDto>();

                locations = new Dtos.GetLocationOutput
                {
                    Locations = Mapper.Map<List<Dtos.LocationDto>>(cities)
                }.Locations;

                var query = (from cv in criteriaOutput.CriteriaValues
                             from l in locations
                             where l.City == cv.Name
                             select new Dtos.LocationDto
                             {
                                 City = l.City,
                                 CreationTime = l.CreationTime,
                                 CreatorUserId = l.CreatorUserId,
                                 State = l.State,
                                 LastModificationTime = l.LastModificationTime,
                                 LastModifierUserId = l.LastModifierUserId,
                                 Id = cv.Id,
                                 CreditCount = cv.CreditCount,
                                 CriteriaRefId = cv.CriteriaRefId,
                                 Name = cv.Name
                             }).ToList<Dtos.LocationDto>();

                return new Dtos.GetLocationOutput() { Locations = query };
            }
            else
            {
                return new Dtos.GetLocationOutput() { Locations = new List<Dtos.LocationDto>() };
            }
        }
 public CreditsHero.Common.Dtos.GetCriteriaValuesOutput GetCriteriaValues(CreditsHero.Common.Dtos.GetCriteriaInput input)
 {
     CreditsHero.Common.Dtos.GetCriteriaValuesOutput results = new CreditsHero.Common.Dtos.GetCriteriaValuesOutput();
     return (CreditsHero.Common.Dtos.GetCriteriaValuesOutput)_creditsHeroConnect.CallCreditsHeroService<CreditsHero.Common.Dtos.GetCriteriaValuesOutput>(results, input,
         "api/services/app/Criteria/GetCriteriaValues");
 }
        public Dtos.GetRoofTypeOutput GetRoofTypes(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 = _roofTypeRepository.GetAll();

            List <Dtos.RoofTypeDto> roofTypes = new List <Dtos.RoofTypeDto>();

            roofTypes = new Dtos.GetRoofTypeOutput
            {
                RoofTypes = Mapper.Map <List <Dtos.RoofTypeDto> >(types)
            }.RoofTypes;

            //var mergeResults = criteriaOutput.CriteriaValues.Select(s => new Dtos.RoofTypeDto { Name = s.Name, Id = s.Id, CreditCount = s.CreditCount, CriteriaRefId = s.CriteriaRefId }).ToList();
            //mergeResults.AddRange(roofTypes.Select(s => new Dtos.RoofTypeDto{Name = s.Name, CreditCount = s.CreditCount, CriteriaRefId = s.CriteriaRefId, Id = s.Id, Code = s.Code, CreationTime = s.CreationTime, CreatorUserId = s.CreatorUserId, Description = s.Description, LastModificationTime = s.LastModificationTime, LastModifierUserId = s.LastModifierUserId}).ToList());
            //List<CreditsHero.Common.Dtos.CriteriaValuesDto> roofTypeList = roofTypes.Concat(criteriaOutput.CriteriaValues).ToList();

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

            return(new Dtos.GetRoofTypeOutput()
            {
                RoofTypes = query
            });
            //roofTypeResults = roofTypeResults.Union(criteriaOutput.CriteriaValues);
        }
        public Dtos.GetRoofTypeOutput GetRoofTypes(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 = _roofTypeRepository.GetAll();

            List<Dtos.RoofTypeDto> roofTypes = new List<Dtos.RoofTypeDto>();

            roofTypes = new Dtos.GetRoofTypeOutput
                         {
                             RoofTypes = Mapper.Map<List<Dtos.RoofTypeDto>>(types)
                         }.RoofTypes;

            //var mergeResults = criteriaOutput.CriteriaValues.Select(s => new Dtos.RoofTypeDto { Name = s.Name, Id = s.Id, CreditCount = s.CreditCount, CriteriaRefId = s.CriteriaRefId }).ToList();
            //mergeResults.AddRange(roofTypes.Select(s => new Dtos.RoofTypeDto{Name = s.Name, CreditCount = s.CreditCount, CriteriaRefId = s.CriteriaRefId, Id = s.Id, Code = s.Code, CreationTime = s.CreationTime, CreatorUserId = s.CreatorUserId, Description = s.Description, LastModificationTime = s.LastModificationTime, LastModifierUserId = s.LastModifierUserId}).ToList());
            //List<CreditsHero.Common.Dtos.CriteriaValuesDto> roofTypeList = roofTypes.Concat(criteriaOutput.CriteriaValues).ToList();

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

            return new Dtos.GetRoofTypeOutput() { RoofTypes = query };
            //roofTypeResults = roofTypeResults.Union(criteriaOutput.CriteriaValues);
        }
        /// <summary>
        /// Gets list of Cities
        /// </summary>
        /// <returns></returns>
        public Dtos.GetLocationOutput GetCities(CreditsHero.Common.Dtos.GetCriteriaInput input, string state)
        {
            if (state != String.Empty)
            {
                #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

                var cities = _locationRepository.GetCities(state);

                List <Dtos.LocationDto> locations = new List <Dtos.LocationDto>();

                locations = new Dtos.GetLocationOutput
                {
                    Locations = Mapper.Map <List <Dtos.LocationDto> >(cities)
                }.Locations;

                var query = (from cv in criteriaOutput.CriteriaValues
                             from l in locations
                             where l.City == cv.Name
                             select new Dtos.LocationDto
                {
                    City = l.City,
                    CreationTime = l.CreationTime,
                    CreatorUserId = l.CreatorUserId,
                    State = l.State,
                    LastModificationTime = l.LastModificationTime,
                    LastModifierUserId = l.LastModifierUserId,
                    Id = cv.Id,
                    CreditCount = cv.CreditCount,
                    CriteriaRefId = cv.CriteriaRefId,
                    Name = cv.Name
                }).ToList <Dtos.LocationDto>();

                return(new Dtos.GetLocationOutput()
                {
                    Locations = query
                });
            }
            else
            {
                return(new Dtos.GetLocationOutput()
                {
                    Locations = new List <Dtos.LocationDto>()
                });
            }
        }
        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 CreditsHero.Common.Dtos.GetCriteriaValuesOutput GetCriteriaValues(CreditsHero.Common.Dtos.GetCriteriaInput input)
 {
     CreditsHero.Common.Dtos.GetCriteriaValuesOutput results = new CreditsHero.Common.Dtos.GetCriteriaValuesOutput();
     return((CreditsHero.Common.Dtos.GetCriteriaValuesOutput)_creditsHeroConnect.CallCreditsHeroService <CreditsHero.Common.Dtos.GetCriteriaValuesOutput>(results, input,
                                                                                                                                                          "api/services/app/Criteria/GetCriteriaValues"));
 }