public void UpdateMerchant(merchant Merchant) { List <merchant> tMerchantList = (from m in m_DB.merchants where (m.id == Merchant.id) select m).ToList <merchant>(); if (tMerchantList.Count == 1) { merchant tMerchnant = tMerchantList.First <merchant>(); tMerchnant = Merchant; m_DB.SaveChanges(); } }
private bool processBizHours(List <Period> tTime, ref merchant Merchant) { Merchant.biz_hours = new List <biz_hours>(); foreach (Period tPeriod in tTime) { biz_hours tHours = new biz_hours(); tHours.day_of_week = tPeriod.open.day; tHours.start_time = tPeriod.open.time; tHours.end_time = tPeriod.close.time; tHours.merchant_id = Merchant.id; Merchant.biz_hours.Add(tHours); } return(true); }
public bool Process(RootObject PlaceDetailResponse) { if (PlaceDetailResponse == null) { return(false); } merchant tMerchant = (from m in DB.merchants where m.place_id == PlaceDetailResponse.result.place_id select m).ToList <merchant>().First(); tMerchant.name = PlaceDetailResponse.result.name; string tAddress, tSubLocality, tCity, tPostalcode, tState, tCountry; DeformatAddress.Process(PlaceDetailResponse.result.formatted_address, out tAddress, out tSubLocality, out tCity, out tPostalcode, out tState, out tCountry); tMerchant.address = tAddress; tMerchant.sublocality = tSubLocality; tMerchant.city = tCity; tMerchant.zipcode = tPostalcode; tMerchant.state = tState; tMerchant.country = tCountry; tMerchant.advertiser = "N"; tMerchant.amenities = null; tMerchant.bills = null; biz_hours tBizTime; List <biz_hours> tBizHourList = new List <biz_hours>(); foreach (Period tHours in PlaceDetailResponse.result.opening_hours.periods) { ParseBizHours(tHours, out tBizTime); tBizHourList.Add(tBizTime); } tMerchant.biz_hours = tBizHourList; tMerchant.latitude = float.Parse(PlaceDetailResponse.result.geometry.location.lat.ToString()); tMerchant.longitude = float.Parse(PlaceDetailResponse.result.geometry.location.lng.ToString()); tMerchant.opt_out = "N"; tMerchant.permanent_cell_phone_number = PlaceDetailResponse.result.formatted_phone_number; tMerchant.thumbnail_photo_url = PlaceDetailResponse.result.icon; tMerchant.website = PlaceDetailResponse.result.website; DB.merchants.Add(tMerchant); DB.SaveChanges(); return(true); }
public bool GetPlaceDetails(merchant Merchant, out RootObject PlaceDetail) { String tSearchStr = SearchStr + "&placeid=" + Merchant.place_id; PlaceDetail = null; System.Net.WebClient http = new System.Net.WebClient(); try { System.IO.Stream tStream = http.OpenRead(tSearchStr); if (tStream != null) { System.IO.StreamReader tReader = new System.IO.StreamReader(tStream); String tResponse = tReader.ReadToEnd(); PlaceDetail = (RootObject)JsonConvert.DeserializeObject(tResponse, typeof(RootObject)); if (PlaceDetail.status.ToUpper() != "OK") { System.Console.WriteLine("TextSearch return a not OK response."); return(false); } tReader.Dispose(); } } catch (WebException ex) { String tMessage = ex.Message + ex.InnerException == null ? "" : " InnerException : " + ex.InnerException.Message; System.Console.WriteLine(tMessage); return(false); } catch (Exception ex) { String tMessage = ex.Message + ex.InnerException == null ? "" : " InnerException : " + ex.InnerException.Message; System.Console.WriteLine(tMessage); return(false); } finally { http.Dispose(); } return(true); }
public void ProcessMerchantDetail(RootObject tSearch) { merchant tMerchant = (from m in m_DB.merchants where (m.place_id == tSearch.result.place_id) select m).SingleOrDefault <merchant>(); if (tMerchant != null) { String tAddress, tSubDivision, tCity, tZip, tState, tCountry; DeformatAddress.Process(tSearch.result.formatted_address, out tAddress, out tSubDivision, out tCity, out tZip, out tState, out tCountry); tMerchant.address = tAddress; tMerchant.sublocality = tSubDivision; tMerchant.city = tCity; tMerchant.state = tState; tMerchant.zipcode = tZip; foreach (AddressComponent taddr in tSearch.result.address_components) { if (tState.Trim().ToUpper() == taddr.long_name.Trim().ToUpper()) { tMerchant.state = taddr.short_name; } if (tCountry.Trim().ToUpper() == taddr.long_name.Trim().ToUpper()) { tMerchant.country = taddr.short_name; } } tMerchant.phone = tSearch.result.international_phone_number; tMerchant.latitude = tSearch.result.geometry.location.lat; tMerchant.longitude = tSearch.result.geometry.location.lng; if (tSearch.result.opening_hours != null) { processBizHours(tSearch.result.opening_hours.periods, ref tMerchant); } tMerchant.updated_at = DateTime.Now; DB.merchants.Attach(tMerchant); DB.Entry(tMerchant).State = System.Data.Entity.EntityState.Modified; try { DB.SaveChanges(); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } catch (DbUpdateException ex) { Console.WriteLine(" Update Exception:" + ex.Message); throw; } catch (Exception ex) { Console.WriteLine("Exception : " + ex.Message); throw; } } }