Ejemplo n.º 1
0
        public IActionResult CreateLocation(string id)
        {
            var listing = businessRepo.GetById(id);
            var vm      = new BusinessDetailsViewModel(listing);

            return(View(vm));
        }
Ejemplo n.º 2
0
        public IActionResult CreateLocation(BusinessDetailsViewModel model)
        {
            var listing = businessRepo.GetById(model.Id);

            foreach (var item in model.Listing.Location)
            {
                listing.Location.Add(item);
            }
            listing = businessRepo.Update(listing);
            return(RedirectToAction("Review", new { id = listing.Id.ToString() }));
        }
        public async Task <ActionResult> AddToDate(BusinessDetailsViewModel businessDetailViewModel)
        {
            var user = await GetUserAsync();

            var client = new HttpClient();

            var yelpAccount = new YelpAccount();

            _config.GetSection("YelpAccount").Bind(yelpAccount);

            var authToken = yelpAccount.KEY;

            client.DefaultRequestHeaders.Add("Authorization", "Bearer " + $"{authToken}");
            client.DefaultRequestHeaders.Add("Accept", "application/json");
            client.DefaultRequestHeaders.Add("User-Agent", "DateNiteYelpClient");

            var response = await client.GetAsync($"https://api.yelp.com/v3/businesses/{businessDetailViewModel.Business.BusinessId}");

            if (response.IsSuccessStatusCode)
            {
                var responseStream = await response.Content.ReadAsStreamAsync();

                var data = await JsonSerializer.DeserializeAsync <Business>(responseStream);

                var date = await _context.Dates.FirstOrDefaultAsync(d => d.UserId == user.Id && d.IsScheduled == false);

                var newBusiness = new Business()
                {
                    BusinessId      = data.BusinessId,
                    Name            = data.Name,
                    Img             = data.Img,
                    Phone           = data.Phone,
                    Price           = data.Price,
                    LocationAddress = data.LocationAddress,
                    Rating          = data.Rating,
                    LocationTypeId  = businessDetailViewModel.Business.LocationTypeId,
                    UserId          = user.Id,
                    DateId          = date.Id
                };

                _context.Businesses.Add(newBusiness);

                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Dates"));
            }

            throw new Exception("Unable to retrieve data from Yelp");
        }
Ejemplo n.º 4
0
        public IActionResult RenderLocationPartial(string viewName, string listingId)
        {
            var listing = businessRepo.GetById(listingId);
            var vm      = new BusinessDetailsViewModel(listing);

            vm.Listing.Location = Enumerable.Repeat("", 10).ToList();
            if (viewName == "NYC")
            {
                listing.Location[0] = "NY";
                listing.Location[2] = "NYC";
            }
            string viewPath = string.Format("~/Views/Businesses/LocationPartials/_{0}.cshtml", viewName);

            return(PartialView(viewPath, vm));
        }
        // GET: Businesses/Details/5
        public async Task <ActionResult> Details(string id)
        {
            var viewModel = new BusinessDetailsViewModel();

            var client = new HttpClient();

            var yelpAccount = new YelpAccount();

            _config.GetSection("YelpAccount").Bind(yelpAccount);

            var authToken = yelpAccount.KEY;

            client.DefaultRequestHeaders.Add("Authorization", "Bearer " + $"{authToken}");
            client.DefaultRequestHeaders.Add("Accept", "application/json");
            client.DefaultRequestHeaders.Add("User-Agent", "DateNiteYelpClient");

            var response = await client.GetAsync($"https://api.yelp.com/v3/businesses/{id}");

            if (response.IsSuccessStatusCode)
            {
                var responseStream = await response.Content.ReadAsStreamAsync();

                var data = await JsonSerializer.DeserializeAsync <Business>(responseStream);

                viewModel.Business = data;

                var locationTypesOptions = await _context.LocationTypes.Select(pt => new SelectListItem()
                {
                    Text  = pt.Type,
                    Value = pt.LocationTypeId.ToString()
                }).ToListAsync();

                viewModel.LocationTypesOptions = locationTypesOptions;

                return(View(viewModel));
            }

            throw new Exception("Unable to retrieve data from Yelp");
        }