/* * // Constructor parameterless - for saving if needed. * public AutoRepairShopInfo() * { * } */ // Constructor - initialize property values from autoRepairWCF public AutoRepairShopInfo(AutoRepairDTO autoRepairDTO) { this.ID = autoRepairDTO.ID; this.Name = autoRepairDTO.Name; this.Address = autoRepairDTO.Address; this.City = autoRepairDTO.City; this.Phone = autoRepairDTO.Phone; this.Url = autoRepairDTO.Url; this.Geolocation = autoRepairDTO.Geolocation; }
private void TranslateAutoRepairDTOToAutoRepairWCF(AutoRepairDTO autoRepairDTO, AutoRepairWCF autoRepairWCF) { autoRepairWCF.ID = autoRepairDTO.ID; autoRepairWCF.Name = autoRepairDTO.Name; autoRepairWCF.Address = autoRepairDTO.Address; autoRepairWCF.City = autoRepairDTO.City; autoRepairWCF.Phone = autoRepairDTO.Phone; autoRepairWCF.Url = autoRepairDTO.Url; autoRepairWCF.Geolocation = autoRepairDTO.Geolocation; }
/* * // 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; }
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); }
//public AutoRepairShop GetNearestAutoRepair(System.Data.Entity.Spatial.DbGeography userLocation) public AutoRepairDTO GetNearestAutoRepair(string userLocation) { AutoRepairDTO autoRepairDTO = null; try { var place = (from u in context.AutoRepairShops // userLocation-> two numbers without comma between, only for decimal spot => "45.758041 15.960335" //orderby u.Geolocation.Distance(DbGeography.FromText(userLocation)) orderby u.Geolocation.Distance(DbGeography.FromText(("POINT(" + userLocation + ")"))) select u).FirstOrDefault(); if (place != null) { autoRepairDTO = new AutoRepairDTO() { ID = place.Id, Name = place.Name, Address = place.Address, City = place.City, Phone = place.Phone, Url = place.Url, //Geolocation = place.Geolocation.ToString() // to get only coordinates, without POINT, SRID and rest Geolocation = place.Geolocation.Latitude.ToString() + " " + place.Geolocation.Longitude.ToString() //RowVersion = product.RowVersion } } ; return(autoRepairDTO); } catch (InvalidOperationException IOE) { // Problem with ConnectionString in config file // connectionString="metadata=res://*/[FileName].csdl|res://*/[FileName].ssdl|res://*/[FileName].msl;provider=System.Data.SqlClient; //Cannot Create the Connection! throw IOE; } catch (MetadataException ME) { // Problem with file => metadata=res://*/[FileName].csdl //Cannot Create the Connection! throw ME; } catch (System.Data.SqlClient.SqlException SqlEx) { // Inherits from System.Data.Common.DbException // Cannot Open the Database! throw SqlEx; } catch (EntityException EE) { // There was a problem reading data. Try again. throw EE; } catch (DataException DE) { //Unexpected Data Exception! throw DE; } catch (Exception Ex) { // Unexpected Error! throw Ex; } }