Exemplo n.º 1
0
        public ActionResult Provide(int id, FeedbackViewModel feedback)
        {
            // Check for request integrity
            if (id != feedback.ReviewId) {
                return new HttpStatusCodeResult(HttpStatusCode.Forbidden, "Not allowed.");
            }

            if (feedback.IsIncomplete) {
                TempData["Message"] = "Please fill out all ratings.";
                return View(feedback);
            }

            var reviewFeedback = new ReviewFeedback
                                 	{
                                 		Reviewer = _db.UserProfiles.FirstOrDefault(user => user.EmailAddress == User.Identity.Name)
                                 	};

            var reviewconfiguration = _db.ReviewConfigurations.Find(id);
            _db.Entry(reviewconfiguration).Collection(c => c.Feedback).Load();

            foreach (var categoriesWithPeersAndRating in feedback.CategoriesWithPeersAndRatings) {
                foreach (var peersWithRating in categoriesWithPeersAndRating.PeersWithRatings) {
                    var assessment = new Assessment
                                     	{
                                     		Rating = peersWithRating.Rating,
                                     		Reviewer = reviewFeedback.Reviewer,
                                     		ReviewCategory = _db.ReviewCategories.Find(categoriesWithPeersAndRating.Category.CatId),
                                     		ReviewedPeer = _db.UserProfiles.Find(peersWithRating.Peer.UserId)
                                     	};
                    reviewFeedback.Assessments.Add(assessment);
                }
            }

            reviewconfiguration.Feedback.Add(reviewFeedback);
            _db.SaveChanges();

            SendMailToPeersIfAllHaveProvidedFeedback(reviewconfiguration);

            TempData["Message"] = "Review has been completed.";
            return RedirectToAction("Index");
        }
Exemplo n.º 2
0
        public ActionResult Provide(int id = 0)
        {
            var reviewconfiguration = _db.ReviewConfigurations.Find(id);
            _db.Entry(reviewconfiguration).Collection(c => c.Categories).Load();
            _db.Entry(reviewconfiguration).Collection(c => c.Peers).Load();

            var feedback = new FeedbackViewModel { ReviewId = id, ReviewName = reviewconfiguration.Name };

            foreach (var reviewCategory in reviewconfiguration.Categories) {
                var categoryWithPeersAndRatings = new CategoryWithPeersAndRatings();
                categoryWithPeersAndRatings.Category = Mapper.Map<CategoryShowModel>(reviewCategory);
                foreach (var peer in reviewconfiguration.Peers) {
                    var peerWithRating = new PeerWithRating { Peer = Mapper.Map<PeerShowModel>(peer), Rating = -1 };
                    categoryWithPeersAndRatings.PeersWithRatings.Add(peerWithRating);
                }
                feedback.CategoriesWithPeersAndRatings.Add(categoryWithPeersAndRatings);
            }
            return View(feedback);
        }