Beispiel #1
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;
        }
 ///////////
 // if there is no 'ref' keyword then autoRepairWCFList is null and nothing (empty list) gets passed to the client
 private void TranslateAutoRepairShopDTOListToAutoRepairShopInfoSList(List<AutoRepairDTO> autoRepairShopDTOList, ref AutoRepairShopInfoList autoRepairShopInfoList)
 {
     foreach (AutoRepairDTO item in autoRepairShopDTOList)
     {
         autoRepairShopInfoList.AutoRepairShopInfos.Add(new AutoRepairShopInfoS()
                                                         { ID= item.ID,
                                                           Name = item.Name,
                                                           Address = item.Address,
                                                           City = item.City,
                                                           Geolocation = item.Geolocation,
                                                           Phone = item.Phone,
                                                           Url = item.Url
                                                         });
     }
 }
Beispiel #4
0
 ///////////
 // if there is no 'ref' keyword then autoRepairWCFList is null and nothing (empty list) gets passed to the client
 private void TranslateAutoRepairShopDTOListToAutoRepairShopInfoSList(List <AutoRepairDTO> autoRepairShopDTOList, ref AutoRepairShopInfoList autoRepairShopInfoList)
 {
     foreach (AutoRepairDTO item in autoRepairShopDTOList)
     {
         autoRepairShopInfoList.AutoRepairShopInfos.Add(new AutoRepairShopInfoS()
         {
             ID          = item.ID,
             Name        = item.Name,
             Address     = item.Address,
             City        = item.City,
             Geolocation = item.Geolocation,
             Phone       = item.Phone,
             Url         = item.Url
         });
     }
 }