Beispiel #1
0
        /*
         * // Another way to convert AutoRepairDTO list to AutoRepairWCF list
         * private List<AutoRepairShopInfo> TranslateAutoRepairShopDTOListToAutoRepairShopInfoList2(List<AutoRepairDTO> autoRepairShopDTOList)
         * {
         *  List<AutoRepairShopInfo> autoRepairShopInfoList = autoRepairShopDTOList.ConvertAll(x => new AutoRepairShopInfo
         *  {
         *      ID = x.ID,
         *      Name = x.Name,
         *      Address = x.Address,
         *      City = x.City,
         *      Phone = x.Phone,
         *      Url = x.Url,
         *      Geolocation = x.Geolocation.ToString()
         *      //RowVersion = product.RowVersion
         *  });
         *  return autoRepairShopInfoList;
         * }
         */

        /* */ // AutoRepairShopRequestObject - check for License Key or UserName and Password
        public AutoRepairShopInfo GetNearestAutoRepairRequest(AutoRepairShopRequest autoRepairShopRequest)
        {
            //AutoRepairDTO autoRepairDTO = null;
            // AutoRepairShopInfo autoRepairShopInfoObject = new AutoRepairShopInfo();

            try
            {
                using (AutoRepairShopRepositoryBLL context = new AutoRepairShopRepositoryBLL())
                {
                    AutoRepairDTO autoRepairDTO = null;
                    // AutoRepairShopRequestObject
                    autoRepairDTO = context.GetNearestAutoRepair(autoRepairShopRequest.Geolocation);

                    AutoRepairShopInfo autoRepairShopInfoObject = new AutoRepairShopInfo(autoRepairDTO);
                    //TranslateAutoRepairDTOToAutoRepairShopInfoObject(autoRepairDTO, autoRepairShopInfoObject);
                    //autoRepairShopInfoObject = context.GetNearestAutoRepair(autoRepairShopRequest.Geolocation);
                    return(autoRepairShopInfoObject);
                }
            }
            catch (Exception ex)
            {
                throw new FaultException <AutoRepairFault>(
                          new AutoRepairFault
                {
                    ErrorMessage = ex.Message,
                    Source       = ex.Source,
                    StackTrace   = ex.StackTrace,
                    Target       = ex.TargetSite.ToString()
                },
                          new FaultReason(string.Format(CultureInfo.InvariantCulture, "{0}", "Service fault exception: " + ex.Message)));
            }

            /*
             * if (autoRepairShopInfoObject == null)
             * {
             *  string msg = string.Format("No AutoRepairShop found for user location {0}", autoRepairShopRequest.Geolocation);
             *  throw new FaultException<AutoRepairFault>(new AutoRepairFault
             *  {
             *      ErrorMessage = msg,
             *      Source = null,
             *      StackTrace = null,
             *      Target = null
             *  },
             *      new FaultReason(string.Format(CultureInfo.InvariantCulture, "{0}", "Service fault exception: " + msg)));
             * }
             */
            //return autoRepairShopInfoObject;
        }
Beispiel #2
0
        /**/

        /*
         * private void TranslateAutoRepairDTOToAutoRepairShopInfoObject(AutoRepairDTO autoRepairDTO, AutoRepairShopInfo autoRepairShopInfoObject)
         * {
         *  autoRepairShopInfoObject.ID = autoRepairDTO.ID;
         *  autoRepairShopInfoObject.Name = autoRepairDTO.Name;
         *  autoRepairShopInfoObject.Address = autoRepairDTO.Address;
         *  autoRepairShopInfoObject.City = autoRepairDTO.City;
         *  autoRepairShopInfoObject.Phone = autoRepairDTO.Phone;
         *  autoRepairShopInfoObject.Url = autoRepairDTO.Url;
         *  autoRepairShopInfoObject.Geolocation = autoRepairDTO.Geolocation;
         * }
         */

        /**/

        /*
         * // if there is no 'ref' keyword then autoRepairWCFList is null and nothing (empty list) gets passed to the client
         * private void TranslateAutoRepairShopDTOListToAutoRepairShopInfoList(List<AutoRepairDTO> autoRepairShopDTOList, ref List<AutoRepairShopInfo> autoRepairShopInfoObjectList)
         * {
         *  autoRepairShopInfoObjectList = autoRepairShopDTOList.ConvertAll(x => new AutoRepairShopInfo
         *  {
         *      ID = x.ID,
         *      Name = x.Name,
         *      Address = x.Address,
         *      City = x.City,
         *      Phone = x.Phone,
         *      Url = x.Url,
         *      Geolocation = x.Geolocation.ToString()
         *      //RowVersion = product.RowVersion
         *  });
         * }
         */


        /**/
        // stackoverflow.com/questions/13739729/wcf-messagecontract-wrapping-and-lists
        // forums.asp.net/t/1775946.aspx?WCF+Service+returning+an+array+instead+of+the+response+object+defined+in+the+Message+Contract
        public AutoRepairShopInfoList GetFiveNearestAutoRepairRequest(AutoRepairShopRequest autoRepairShopRequest)
        {
            List <AutoRepairDTO>   autoRepairDTOList      = new List <AutoRepairDTO>();
            AutoRepairShopInfoList autoRepairShopInfoList = new AutoRepairShopInfoList();

            try
            {
                using (AutoRepairShopRepositoryBLL context = new AutoRepairShopRepositoryBLL())
                {
                    autoRepairDTOList = context.GetFiveNearestAutoRepairs(autoRepairShopRequest.Geolocation);
                    TranslateAutoRepairShopDTOListToAutoRepairShopInfoSList(autoRepairDTOList, ref autoRepairShopInfoList);
                }
            }
            catch (Exception ex)
            {
                //Part 18 Throwing fault exceptions from a WCF service
                throw new FaultException <AutoRepairFault>(
                          new AutoRepairFault
                {
                    ErrorMessage = ex.Message,
                    Source       = ex.Source,
                    StackTrace   = ex.StackTrace,
                    Target       = ex.TargetSite.ToString()
                },
                          new FaultReason(string.Format(CultureInfo.InvariantCulture, "{0}", "Service fault exception: " + ex.Message)));
            }

            if (autoRepairShopInfoList == null)
            {
                string msg = string.Format("No Auto Repair Shop found.");
                throw new FaultException <AutoRepairFault>(new AutoRepairFault
                {
                    ErrorMessage = msg,
                    Source       = null,
                    StackTrace   = null,
                    Target       = null
                },
                                                           new FaultReason(string.Format(CultureInfo.InvariantCulture, "{0}", "Service fault exception: " + msg)));
            }

            return(autoRepairShopInfoList);
        }
        public AutoRepairShopInfoList GetAllAutoRepairRequest(AutoRepairShopRequest autoRepairShopRequest)
        {
            List<AutoRepairDTO> autoRepairDTOList = new List<AutoRepairDTO>();
            AutoRepairShopInfoList autoRepairShopInfoList = new AutoRepairShopInfoList();

            try
            {
                using (AutoRepairShopRepositoryBLL context = new AutoRepairShopRepositoryBLL())
                {
                    autoRepairDTOList = context.GetAllAutoRepairs();
                    TranslateAutoRepairShopDTOListToAutoRepairShopInfoSList(autoRepairDTOList, ref autoRepairShopInfoList);
                }
            }
            catch (Exception ex)
            {
                //Part 18 Throwing fault exceptions from a WCF service
                throw new FaultException<AutoRepairFault>(
                    new AutoRepairFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        StackTrace = ex.StackTrace,
                        Target = ex.TargetSite.ToString()
                    },
                    new FaultReason(string.Format(CultureInfo.InvariantCulture, "{0}", "Service fault exception: " + ex.Message)));
            }

            if (autoRepairShopInfoList == null)
            {
                string msg = string.Format("No Auto Repair Shop found.");
                throw new FaultException<AutoRepairFault>(new AutoRepairFault
                {
                    ErrorMessage = msg,
                    Source = null,
                    StackTrace = null,
                    Target = null
                },
                    new FaultReason(string.Format(CultureInfo.InvariantCulture, "{0}", "Service fault exception: " + msg)));
            }
            return autoRepairShopInfoList;
        }
        /**/
        /*
        private void TranslateAutoRepairDTOToAutoRepairShopInfoObject(AutoRepairDTO autoRepairDTO, AutoRepairShopInfo autoRepairShopInfoObject)
        {
            autoRepairShopInfoObject.ID = autoRepairDTO.ID;
            autoRepairShopInfoObject.Name = autoRepairDTO.Name;
            autoRepairShopInfoObject.Address = autoRepairDTO.Address;
            autoRepairShopInfoObject.City = autoRepairDTO.City;
            autoRepairShopInfoObject.Phone = autoRepairDTO.Phone;
            autoRepairShopInfoObject.Url = autoRepairDTO.Url;
            autoRepairShopInfoObject.Geolocation = autoRepairDTO.Geolocation;
        }
        */
        /**/
        /*
        // if there is no 'ref' keyword then autoRepairWCFList is null and nothing (empty list) gets passed to the client
        private void TranslateAutoRepairShopDTOListToAutoRepairShopInfoList(List<AutoRepairDTO> autoRepairShopDTOList, ref List<AutoRepairShopInfo> autoRepairShopInfoObjectList)
        {
            autoRepairShopInfoObjectList = autoRepairShopDTOList.ConvertAll(x => new AutoRepairShopInfo
            {
                ID = x.ID,
                Name = x.Name,
                Address = x.Address,
                City = x.City,
                Phone = x.Phone,
                Url = x.Url,
                Geolocation = x.Geolocation.ToString()
                //RowVersion = product.RowVersion
            });
        }
           */
        /**/
        // stackoverflow.com/questions/13739729/wcf-messagecontract-wrapping-and-lists
        // forums.asp.net/t/1775946.aspx?WCF+Service+returning+an+array+instead+of+the+response+object+defined+in+the+Message+Contract
        public AutoRepairShopInfoList GetFiveNearestAutoRepairRequest(AutoRepairShopRequest autoRepairShopRequest)
        {
            List<AutoRepairDTO> autoRepairDTOList = new List<AutoRepairDTO>();
            AutoRepairShopInfoList autoRepairShopInfoList = new AutoRepairShopInfoList();

            try
            {
                using (AutoRepairShopRepositoryBLL context = new AutoRepairShopRepositoryBLL())
                {
                autoRepairDTOList = context.GetFiveNearestAutoRepairs(autoRepairShopRequest.Geolocation);
                TranslateAutoRepairShopDTOListToAutoRepairShopInfoSList(autoRepairDTOList, ref autoRepairShopInfoList);
               }
            }
            catch (Exception ex)
            {
                //Part 18 Throwing fault exceptions from a WCF service
                throw new FaultException<AutoRepairFault>(
                    new AutoRepairFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        StackTrace = ex.StackTrace,
                        Target = ex.TargetSite.ToString()
                    },
                    new FaultReason(string.Format(CultureInfo.InvariantCulture, "{0}", "Service fault exception: " + ex.Message)));
            }

            if (autoRepairShopInfoList == null)
            {
                string msg = string.Format("No Auto Repair Shop found.");
                throw new FaultException<AutoRepairFault>(new AutoRepairFault
                {
                    ErrorMessage = msg,
                    Source = null,
                    StackTrace = null,
                    Target = null
                },
                    new FaultReason(string.Format(CultureInfo.InvariantCulture, "{0}", "Service fault exception: " + msg)));
            }

              return autoRepairShopInfoList;
        }

        // Nearest 5 Auto Repair Shops
        public List<AutoRepairWCF> GetFiveNearestAutoRepairs(string userLocation)
        {
            List<AutoRepairDTO> autoRepairDTOList = new List<AutoRepairDTO>();
            List<AutoRepairWCF> autoRepairWCFList = new List<AutoRepairWCF>();
            try
            {
                using (AutoRepairShopRepositoryBLL context = new AutoRepairShopRepositoryBLL())
                {
                    autoRepairDTOList = context.GetFiveNearestAutoRepairs(userLocation);
                    TranslateAutoRepairShopDTOListToAuotoRepairWCFList(autoRepairDTOList, ref autoRepairWCFList);
                }
            }
            catch (Exception ex)
            {
                //Part 18 Throwing fault exceptions from a WCF service
                //throw new FaultException();
                throw new FaultException<AutoRepairFault>(
                    new AutoRepairFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        StackTrace = ex.StackTrace,
                        Target = ex.TargetSite.ToString()
                    },
                    new FaultReason(string.Format(CultureInfo.InvariantCulture, "{0}", "Service fault exception: " + ex.Message)));
            }

            if (autoRepairDTOList == null)
            {
                string msg = string.Format("No Auto Repair Shop found.");
                throw new FaultException<AutoRepairFault>(new AutoRepairFault
                {
                    ErrorMessage = msg,
                    Source = null,
                    StackTrace = null,
                    Target = null
                },
                    new FaultReason(string.Format(CultureInfo.InvariantCulture, "{0}", "Service fault exception: " + msg)));
            }

            return autoRepairWCFList;
        }

        public AutoRepairWCF GetNearestAutoRepair(string userLocation)
        {
            AutoRepairDTO autoRepairDTO = null;
            AutoRepairWCF autoRepairWCF = new AutoRepairWCF();

            try
            {
                using (AutoRepairShopRepositoryBLL context = new AutoRepairShopRepositoryBLL())
                {
                    autoRepairDTO = context.GetNearestAutoRepair(userLocation);
                    TranslateAutoRepairDTOToAutoRepairWCF(autoRepairDTO, autoRepairWCF);
                }
            }
            catch (Exception ex)
            {
                throw new FaultException<AutoRepairFault>(
                    new AutoRepairFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        StackTrace = ex.StackTrace,
                        Target = ex.TargetSite.ToString()
                    },
                    new FaultReason(string.Format(CultureInfo.InvariantCulture, "{0}", "Service fault exception: " + ex.Message)));

                // throw new FaultException("Service fault exception: " +ex.Message);
            }

            if (autoRepairDTO == null)
            {
                string msg = string.Format("No AutoRepairShop found for user location {0}", userLocation);
                throw new FaultException<AutoRepairFault>(new AutoRepairFault
                {
                    ErrorMessage = msg,
                    Source = null,
                    StackTrace = null,
                    Target = null
                },
                    new FaultReason(string.Format(CultureInfo.InvariantCulture, "{0}", "Service fault exception: " + msg)));
            }

            return autoRepairWCF;
        }

        /*
        // Another way to convert AutoRepairDTO list to AutoRepairWCF list
        private List<AutoRepairShopInfo> TranslateAutoRepairShopDTOListToAutoRepairShopInfoList2(List<AutoRepairDTO> autoRepairShopDTOList)
        {
            List<AutoRepairShopInfo> autoRepairShopInfoList = autoRepairShopDTOList.ConvertAll(x => new AutoRepairShopInfo
            {
                ID = x.ID,
                Name = x.Name,
                Address = x.Address,
                City = x.City,
                Phone = x.Phone,
                Url = x.Url,
                Geolocation = x.Geolocation.ToString()
                //RowVersion = product.RowVersion
            });
            return autoRepairShopInfoList;
        }
        */
        /* */
        // AutoRepairShopRequestObject - check for License Key or UserName and Password
        public AutoRepairShopInfo GetNearestAutoRepairRequest(AutoRepairShopRequest autoRepairShopRequest)
        {
            //AutoRepairDTO autoRepairDTO = null;
               // AutoRepairShopInfo autoRepairShopInfoObject = new AutoRepairShopInfo();

            try
            {
                using (AutoRepairShopRepositoryBLL context = new AutoRepairShopRepositoryBLL())
                {
                    AutoRepairDTO autoRepairDTO = null;
                                                                // AutoRepairShopRequestObject
                    autoRepairDTO = context.GetNearestAutoRepair(autoRepairShopRequest.Geolocation);

                    AutoRepairShopInfo autoRepairShopInfoObject = new AutoRepairShopInfo(autoRepairDTO);
                    //TranslateAutoRepairDTOToAutoRepairShopInfoObject(autoRepairDTO, autoRepairShopInfoObject);
                    //autoRepairShopInfoObject = context.GetNearestAutoRepair(autoRepairShopRequest.Geolocation);
                    return autoRepairShopInfoObject;
                }
            }
            catch (Exception ex)
            {
                 throw new FaultException<AutoRepairFault>(
                    new AutoRepairFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        StackTrace = ex.StackTrace,
                        Target = ex.TargetSite.ToString()
                    },
                    new FaultReason(string.Format(CultureInfo.InvariantCulture, "{0}", "Service fault exception: " + ex.Message)));
            }
            /*
            if (autoRepairShopInfoObject == null)
            {
                string msg = string.Format("No AutoRepairShop found for user location {0}", autoRepairShopRequest.Geolocation);
                throw new FaultException<AutoRepairFault>(new AutoRepairFault
                {
                    ErrorMessage = msg,
                    Source = null,
                    StackTrace = null,
                    Target = null
                },
                    new FaultReason(string.Format(CultureInfo.InvariantCulture, "{0}", "Service fault exception: " + msg)));
            }
            */
              //return autoRepairShopInfoObject;
        }