public async Task <IActionResult> Post([FromBody] AttractionLike model)
        {
            if (!await MatchAppUserWithToken((int)model.AppUserId))
            {
                return(Unauthorized());
            }

            if (!await _repo.RecordExist("AppUser", (int)model.AppUserId))
            {
                return(NotFound());
            }

            var attractionFromRepo = await _repo.GetAttraction((int)model.AttractionId);

            if (attractionFromRepo == null)
            {
                return(NotFound());
            }

            var likeRecord = await _repo.GetAttractionLike((int)model.AppUserId, (int)model.AttractionId);

            if (await _repo.AttractionLiked((int)model.AppUserId, (int)model.AttractionId))
            {
                return(BadRequest("既にリアクションされています"));
            }

            _repo.Add(model);
            await _appUserRepo.AddLikeCountToUser((int)attractionFromRepo.AppUserId);

            if (await _repo.SaveAll() > 0)
            {
                return(Created("GetAttractionLike", null));
            }
            return(BadRequest("Failed to post attraction like"));
        }
        public async Task <IActionResult> GetAttraction(int id)
        {
            var attraction = await _attractionRepository.GetAttraction(id);

            var attractionResource = AttractionMapper.MapAttractionToAttractionResource(attraction);

            return(Ok(attractionResource));
        }
Exemple #3
0
        public async Task <IActionResult> GetAttractionPhoto(int id, string sufix)
        {
            var attr = await _attractionRepository.GetAttraction(id);

            var attrName = attr.Name + sufix;

            var path  = Path.Combine(_hostingEnvironment.WebRootPath, "AttractionGallery", "User1");
            var image = System.IO.File.OpenRead(path + "\\" + attrName + ".png");

            return(File(image, "image/png"));
        }
        public async Task <ActionResult> Get(int id)
        {
            var attractionFromRepo = await _attractionRepo.GetAttraction(id);

            var attraction = _mapper.Map <AttractionForReturnDto>(attractionFromRepo);

            attraction.ReviewPhotos = _mapper.Map <List <PhotoForReturnDto> >(await _attractionRepo.GetAllReviewPhotosForAttraction(id));
            var loggedInUser = await GetLoggedInUserAsync();

            if (loggedInUser != null)
            {
                attraction.isLiked = await _attractionRepo.AttractionLiked(loggedInUser.Id, attraction.Id);

                var currentUserReview = await _attractionRepo.GetAttractionReviewByUser(loggedInUser.Id, attraction.Id);

                if (currentUserReview != null)
                {
                    attraction.currentUsersReviewId = currentUserReview.Id;
                }
            }
            return(Ok(attraction));
        }
Exemple #5
0
        public IActionResult Index(Route stuff)
        {
            Route           newRoute = _routeRepository.GetUserRoute(User.Identity.Name);
            RouteAttraction route    = new RouteAttraction()
            {
                RouteId     = newRoute.RouteID,
                Route       = newRoute,
                AtractionId = stuff.TempAtractionID,
                Attraction  = _attractionRepository.GetAttraction(stuff.TempAtractionID),
            };

            List <RouteAttraction> routeAttractions = new List <RouteAttraction>();

            if (newRoute.RouteAttractions != null)
            {
                routeAttractions = newRoute.RouteAttractions;
            }

            route.Index = routeAttractions.Count;
            routeAttractions.Add(route);
            newRoute.RouteAttractions = routeAttractions;
            _routeRepository.Update(newRoute);
            return(RedirectToAction("index"));
        }
        public ViewResult Details(int?id)
        {
            var model = _attractionRepository.GetAttraction(id ?? 1);

            return(View(model));
        }