public async Task <ActionResult> _PostReview(Models.VM.CreateReviewVM review)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    TravelerProfile tpcheck = await ProfileManager.LoadUserAndTravelerProfile(User);

                    TravelerProfile tp = await ProfilesController.LoadProfile(review.ID);

                    if (tpcheck.ID == tp.ID)
                    {
                        throw new Exception("Access Violation Post Review! User tried to Review his own profile", new AccessViolationException());
                    }
                    TravelerProfileReviews treviews = tp.Reviews;
                    var             tpRevUpdate     = treviews;
                    TravelerProfile tPoster         = await ProfileManager.LoadUserAndTravelerProfile(User);

                    Review rev = new Review(review, tPoster.ID, tp.TravelerReviewsID);
                    tpRevUpdate.Reviews.Add(rev);
                    using (var db = new ApplicationDbContext())
                    {
                        db.Reviews.Add(rev);

                        await db.SaveChangesAsync();
                    }
                }
                catch (Exception e)
                {
                    NotificationManager.AddException(e);
                    NotificationManager.AddNotification(NotificationType.Error, "Oops, something went wrong!");
                }
            }
            return(RedirectToAction("Details", new { id = review.ID }));
        }
        // GET: TravelerProfiles/Edit/5
        public static async Task <Models.VM.ProfilePreviewVM> ProfilePreviewVM(int id)
        {
            TravelerProfile tp = await ProfilesController.LoadProfile(id);

            float score = 0.0f;

            if (tp.Reviews.Reviews.Count > 0)
            {
                foreach (var rev in tp.Reviews.Reviews)
                {
                    score = score + rev.Ranking;
                }
                score = score / tp.Reviews.Reviews.Count;
            }
            tp.Reviews.Score = score;
            Models.VM.ProfilePreviewVM tpPrev = new Models.VM.ProfilePreviewVM(tp);
            return(tpPrev);
        }
Exemplo n.º 3
0
        private async Task <Models.Find.RequestResults> GetRequestSearchResults(Models.Find.SearchVM searchVM)
        {
            string destination = searchVM.Search.Location;

            Models.Accommodation.Likibu.Destination dest = (await GetGeolocationString(destination, searchVM.Language, "1")).FirstOrDefault();

            string destID = dest.ID;

            using (var db = new ApplicationDbContext())
            {
                IQueryable <Models.Request.Request> retQ = db.Requests.Where(p => p.Accommodation.AccomProfile.DestinationIDs.Contains(destID)).Include(p => p.Accommodation).Include(p => p.Accommodation.AccomProfile); /// Destination Ids have to be updated
                //retQ = FilterCheckTimeRequests(searchVM, retQ, 3.0f);
                retQ = retQ.Where(p => p.objState == BaseDataObject.ObjectState.Valid);
                int totalres = retQ.Count();
                int page     = int.Parse(searchVM.Search.FilterProps.Page);
                int perpage  = int.Parse(searchVM.Search.FilterProps.PerPage);
                IEnumerable <Models.Request.Request> retList = await retQ.ToListAsync();

                if (page > 1)
                {
                    retList = retList.Skip(perpage * (page - 1));
                }
                retList = retList.Take(perpage);


                List <Models.Request.RequestVMListing> retListFiltered = new List <Models.Request.RequestVMListing>();

                foreach (var rq in retList) //Filter invalid requests
                {
                    if (rq.IsValid())
                    {
                        Models.VM.ProfilePreviewVM host = await ProfilesController.ProfilePreviewVM(rq.RequestOwner_ID);

                        retListFiltered.Add(new Models.Request.RequestVMListing(rq, "", host)); //stats
                    }
                }

                searchVM.RequestResults = new Models.Find.RequestResults(retListFiltered, page, perpage, totalres); //int.Parse(searchVM.Search.FilterProps.Page), int.Parse(searchVM.Search.FilterProps.PerPage)
                return(searchVM.RequestResults);
            }
        }