Beispiel #1
0
        public ActionResult EditReview(ReviewSubmitionViewModel model, string Submit)
        {
            _logger.Log("Nomination-EditReview-POST");
            var currentNomination = _nominationService.GetNomination(model.NominationId);
            var customDate        = _customDateService.GetCustomDate(currentNomination.AwardId);
            var alreadyReviewed   = _encourageDatabaseContext.Query <Review>().FirstOrDefault(r => r.ReviewerId == model.ReviewerId && r.NominationId == model.NominationId);
            var previousComments  = _encourageDatabaseContext.Query <ReviewerComment>().Where(r => r.ReviewerId == model.ReviewerId && r.NominationId == model.NominationId).ToList();

            foreach (var previousComment in previousComments)
            {
                _encourageDatabaseContext.Delete <ReviewerComment>(previousComment);
            }
            if (alreadyReviewed != null)
            {
                _encourageDatabaseContext.Delete <Review>(alreadyReviewed);
                _encourageDatabaseContext.SaveChanges();
            }

            var review = new Review();

            review.NominationId = model.NominationId;
            review.ReviewerId   = model.ReviewerId;
            review.ReviewDate   = customDate;


            if (!string.IsNullOrEmpty(Submit) && Submit == "Submit")
            {
                review.IsSubmited = true;
            }

            if (!string.IsNullOrEmpty(Submit) && Submit == "Save Draft")
            {
                review.IsSubmited = false;
            }

            if (!string.IsNullOrEmpty(Submit) && Submit != "Discard Review")
            {
                _nominationService.AddReviewForCurrentNomination(review);

                foreach (var item in model.Comments)
                {
                    var revrComment = new ReviewerComment()
                    {
                        NominationId = model.NominationId,
                        ReviewerId   = model.ReviewerId,
                        CriteriaId   = item.CriteriaId,
                        Comment      = item.Comment != null ? item.Comment : "",
                        Credit       = Convert.ToInt32(item.Credit),
                        ReviewId     = review.Id
                    };
                    _nominationService.AddReviewerCommentsForCurrentNomination(revrComment);
                }
                if (review.IsSubmited == true)
                {
                    _nominationService.UpdateFinalScore(model.NominationId);
                }
            }

            return(RedirectToAction("Index", "Home"));
        }
Beispiel #2
0
 public bool AddReviewer(int userId)
 {
     try
     {
         if (!_encourageDatabaseContext.Query <Reviewer>().Any(r => r.UserId == userId))
         {
             _encourageDatabaseContext.Add <Reviewer>(new Reviewer
             {
                 UserId = userId
             });
             _encourageDatabaseContext.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
     return(false);
 }
 public void AddReviewForCurrentNomination(Review review)
 {
     _encourageDatabaseContext.Add(review);
     _encourageDatabaseContext.SaveChanges();
 }