Example #1
0
        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);
        }
Example #2
0
        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;
                }
            }
        }