Пример #1
0
        /// <summary>
        /// Create a business view model
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        private BusinessViewModel CreateBusinessVM(Business s)
        {
            return new BusinessViewModel()
             {
                 Name = s.Name,
                 Address = s.Address,
                 Phone = s.Phone,
                 SortDescription = s.SortDescription,
                 Information = s.Information,
                 CreateBy = s.CreateBy,
                 Id = s.Id,
                 Active = s.Active,
                 CreateDate = s.CreateDate,
                 Email = s.Email,
                 Category = s.Category,
                 BusinessOwner = s.BusinessOwner,
                 Latitude = s.Latitude,
                 Longtitude = s.Longtitude,
                 Facebook = s.Facebook,
                 Twitter = s.Twitter,
                 BusinessCategoryId = s.BusinessCategoryId,
                 UserId = s.UserId,
                 GooglePlaceIcon = s.GooglePlaceIcon,
                 ImgProfile = s.ImgProfile,
                 TotalComments = s.TotalComments,
                 TotalViewed = s.TotalViewed,
                 Status = s.Status.ToString(),
                 PathGuid  = String.Format("{0}/page/{1}.html",s.Id.ToString().Replace("-",""),s.Name.Replace(" ","_")),

                 TotalRated = (s.Comments != null && s.Comments.Count > 0) ? s.Comments.Average(t => (int)t.BusinessRate) : 0
             };
        }
Пример #2
0
        public ActionResult DownloadInfo(BusinessCategoryViewModel item)
        {
            var userId = User.Identity.GetUserId();
            if (item != null)
            {
                if (item.IsChoose && (item.TotalDownloaded < item.Availble || (item.Availble == 0 && item.TotalDownloaded == 0)))
                {
                    var query = new Query();
                    query.And(
                    query.Field("locality").Equal(item.City),
                    query.Field("region").Equal(item.State),
                    query.Field("postcode").Equal(item.Zipcode),
                    query.Field("category_ids").Includes(item.CategoryInclude),
                    query.IncludeRowCount(true)
                    );
                    try
                    {
                        string re = Factual.Fetch("restaurants-us", query);

                        if (!String.IsNullOrEmpty(re))
                        {
                            Category_ZipCode cate = category_ZipCodeService.Get().FirstOrDefault(t => t.ZipcodeName.Equals(item.Zipcode));
                            if (cate != null)
                            {
                                dynamic jsonResponse = JsonConvert.DeserializeObject(re);
                                //import to business and update Downloaded

                                if (jsonResponse.response != null && jsonResponse.status == "ok")
                                {
                                    dynamic data = jsonResponse.response.data;
                                    dynamic total_row_count = jsonResponse.response.total_row_count;
                                    dynamic included_rows = jsonResponse.response.included_rows;

                                    if (data != null)
                                    {
                                        JArray listData = data as JArray;
                                        if (listData != null)
                                        {
                                            for (int i = 0; i < listData.Count; i++)
                                            {
                                                dynamic biz = listData[i];
                                                //insert to business
                                                Business bus = new Business()
                                                {
                                                    Id = Guid.NewGuid(),
                                                    Address = biz.address,
                                                    Phone = biz.tel,
                                                    Latitude = biz.latitude ?? 0,
                                                    Longtitude = biz.longitude ?? 0,
                                                    Locality = biz.locality,
                                                    Active = true,
                                                    BusinessCategoryId = cate.BusinessCategoryId,
                                                    Country = biz.country,
                                                    CreateBy = HttpContext.User.Identity.Name,
                                                    CreateDate = DateTime.Now,
                                                    Name = biz.name,
                                                    Region = biz.region,
                                                    Status = Infrastructure.Domain.Status.Approved,
                                                    //reference
                                                    UserId = userId,
                                                    Zipcode = item.Zipcode
                                                };

                                                businessService.Create(bus);
                                            }
                                        }
                                    }

                                    cate.TotalRecord = total_row_count == null ? 0 : total_row_count;
                                    cate.Downloaded += cate.TotalRecord;
                                    category_ZipCodeService.Update(cate);

                                    item.TotalDownloaded = cate.Downloaded;
                                    item.Availble = cate.TotalRecord;

                                }
                            }
                        }
                    }
                    catch (FactualApiException ce)
                    {
                    }
                }
            }

            return Json(item, JsonRequestBehavior.AllowGet);
        }
Пример #3
0
        public ActionResult UpdateBusinessInfo(Business business)
        {
            business.CreateBy = User.Identity.Name;

            // For business ower request a new business
            if (business.UserId == null || business.UserId == Guid.Empty.ToString())
            {
                business.UserId = User.Identity.GetUserId();
                business.Status = Status.Pending;
            }

            if (business.Id == Guid.Empty)
            {
                var user = userService.Get(User.Identity.GetUserId());
                business.Status = user.AccountType == AccountType.Administrator ? Status.Approved : Status.Pending;
                var newBiz = businessService.Create(business);
                return Json(new JsonData() { Data = newBiz, Success = true });
            }
            else
            {
                var updateBiz = businessService.Update(business);
                return Json(new JsonData() { Data = business, Success = true });

            }
        }
Пример #4
0
        public void Download(string city, string state, string zipcode, string categories, out int total, out int downloaded)
        {
            int totalDownload = 0;
            int totalDownloaded = 0;

            var query = new Query();
            query.And(
            query.Field("locality").Equal(city),
            query.Field("region").Equal(state),
            query.Field("postcode").Equal(zipcode),
            query.Field("category_ids").Includes(categories),
            query.IncludeRowCount(true)
            );
            try
            {
                string re = Factual.Fetch("restaurants-us", query);

                if (!String.IsNullOrEmpty(re))
                {
                    Category_ZipCode cate = category_ZipCodeService.Get().FirstOrDefault(t => t.ZipcodeName.Equals(zipcode));
                    if (cate != null)
                    {
                        dynamic jsonResponse = JsonConvert.DeserializeObject(re);
                        //import to business and update Downloaded

                        if (jsonResponse.response != null && jsonResponse.status == "ok")
                        {
                            dynamic data = jsonResponse.response.data;
                            dynamic total_row_count = jsonResponse.response.total_row_count;
                            dynamic included_rows = jsonResponse.response.included_rows;

                            if (data != null)
                            {
                                JArray listData = data as JArray;
                                if (listData != null)
                                {
                                    for (int i = 0; i < listData.Count; i++)
                                    {
                                        dynamic biz = listData[i];
                                        //insert to business
                                        Business bus = new Business()
                                        {
                                            Id = Guid.NewGuid(),
                                            Address = biz.address,
                                            Phone = biz.tel,
                                            Latitude = biz.latitude ?? 0,
                                            Longtitude = biz.longitude ?? 0,
                                            Locality = biz.locality,
                                            Active = true,
                                            BusinessCategoryId = cate.BusinessCategoryId,
                                            Country = biz.country,
                                            CreateBy = "Download Tool",
                                            CreateDate = DateTime.Now,
                                            Name = biz.name,
                                            Region = biz.region,
                                            Status = Infrastructure.Domain.Status.Approved,
                                            //reference
                                            UserId = userId,
                                            Zipcode = zipcode
                                        };

                                        businessService.Create(bus);
                                    }
                                }
                            }

                            totalDownload = cate.TotalRecord = total_row_count == null ? 0 : total_row_count;
                            cate.Downloaded += cate.TotalRecord;
                            totalDownloaded = cate.Downloaded;
                            category_ZipCodeService.Update(cate);

                        }
                    }
                }
            }
            catch (FactualApiException ce)
            {
            }
            total = totalDownload;
            downloaded = totalDownloaded;
        }