Esempio n. 1
0
        public bool AddToFavourites(string userId, int reviewId)
        {
            var user = this.DbContext
                       .Users
                       .FirstOrDefault(x => x.Id == userId);

            var review = this.DbContext
                         .Reviews
                         .FirstOrDefault(x => x.Id == reviewId);

            if (user == null || review == null)
            {
                return(false);
            }

            var userReview = new UserReviews()
            {
                UserId              = userId,
                ReviewId            = reviewId,
                AddedToFavouritesOn = DateTime.UtcNow
            };

            bool alreadyInFavourites = this.DbContext.FavouriteUserReviews
                                       .Any(x => x.UserId == userId && x.ReviewId == reviewId);

            if (alreadyInFavourites)
            {
                return(false);
            }

            user.FavouriteReviews.Add(userReview);
            this.DbContext.SaveChanges();

            return(true);
        }
Esempio n. 2
0
        public IHttpActionResult WriteReview(string review, int albumId)
        {
            var userId     = User.Identity.GetUserId();
            var albumInDb  = _context.albums.SingleOrDefault(x => x.albumId == albumId);
            var userReview = _context.userReviews.SingleOrDefault(x => x.album.albumId == albumInDb.albumId && x.userId == userId);

            if (userReview == null)
            {
                userReview = new UserReviews()
                {
                    userId      = userId,
                    album       = albumInDb,
                    review      = review,
                    dateUpdated = DateTime.Now
                };
                _context.userReviews.Add(userReview);
                _context.SaveChanges();
                return(Ok());
            }
            else
            {
                userReview.review      = review;
                userReview.dateUpdated = DateTime.Now;
                _context.SaveChanges();
                return(Ok());
            }
        }
Esempio n. 3
0
        public ActionResult Create([Bind(Exclude = "ReportDate, ", Include = "ReviewID,Rating,Comment, JobID, Reviewee")] Review review, int?job, string employer)
        {
            review.ReportDate = DateTime.UtcNow;
            //review.Reviewee = Reviewee;
            UserReviews rv = new UserReviews();

            rv.ReviewID = review.ReviewID;
            rv.UserID   = User.Identity.GetUserId();

            if (ModelState.IsValid)
            {
                db.Reviews.Add(review);
                db.UserReviews.Add(rv);
                db.SaveChanges();
                TempData["ReviewSuccess"] = "Review successfully submitted";
                return(RedirectToRoute("Default", new { controller = "Jobs", action = "Index" }));
            }

            var userID = User.Identity.GetUserId();

            if (employer != null)
            {
                var jobs = db.Jobs.Where(w => w.JobID == job).Include(e => e.Employer).Include(e => e.Employer.ApplicationUser).Where(e => e.EmployerID == employer);
                ViewBag.JList = jobs;
            }
            else
            {
                var jobs = db.Jobs.Where(w => w.JobID == job).Include(e => e.Employer).Include(e => e.Employer.ApplicationUser).Where(e => e.EmployerID == userID);
                ViewBag.JList = jobs;
            }
            var workers = db.JobApplications.Include(j => j.Job).Include(j => j.Worker).Include(j => j.Worker.ApplicationUser).Include(w => w.Worker).Where(j => j.JobID == job).Where(w => w.Response == Reply.Hired);

            ViewBag.WList = workers;
            return(View(review));
        }
Esempio n. 4
0
        public async Task <IActionResult> PostReview([FromBody] UserReviews newReview)
        {
            var loggedInMember = GetLoggedInMember();

            newReview.ReviewerId = loggedInMember.FirstName + " " + loggedInMember.LastName;
            _context.UserReviews.Add(newReview);
            _context.SaveChanges();

            return(Ok());
        }
Esempio n. 5
0
        [HttpPost] //Метод Rsvp должен применяться только для запросов POST
        public ViewResult RsvpForm(UserReviews review)
        {
            if (ModelState.IsValid)
            {
                //Сохранить отзыв от пользователя
                Repository.AddComment(review);
                //Вернуть благодарность за отзыв
                return(View("RsvpForm", review));
            }

            else
            {
                return(View()); //Обнаружена ошибка проверки достоверности
            }
        }
Esempio n. 6
0
        private void loadReviews()
        {
            flowPanelUserPageReview.Controls.Clear();
            flowPanelUserPageReview.AutoScroll    = true;
            flowPanelUserPageReview.AutoSize      = false;
            flowPanelUserPageReview.FlowDirection = FlowDirection.LeftToRight;
            flowPanelUserPageReview.WrapContents  = true;
            UserReviews        obj    = new UserReviews();
            List <UserReviews> mylist = obj.allReviews(this.userID);

            foreach (UserReviews user in mylist)
            {
                UserPageReviewContainer cont = new UserPageReviewContainer(user.Name, user.Comment, user.Rank);
                flowPanelUserPageReview.Controls.Add(cont);
            }
        }
Esempio n. 7
0
        public decimal AverageRating()
        {
            decimal totalRating = 0M;

            foreach (UserReview review in UserReviews)
            {
                totalRating += review.Rating;
            }

            decimal avgRating = 0M;

            if (UserReviews.Count() != 0)
            {
                avgRating = totalRating / UserReviews.Count();
            }

            decimal roundedAvgRating = Math.Round(avgRating, 1);

            return(roundedAvgRating);
        }