示例#1
0
        public ActionResult SaveFinalScore(ConsolidatedNominationsViewModel consolidatedNominationsViewModel)
        {
            try
            {
                foreach (var nomination in consolidatedNominationsViewModel.Nominations)
                {
                    foreach (var finalComment in nomination.ManagerComments)
                    {
                        var commentDb = _encourageDatabaseContext.Query <ManagerComment>().FirstOrDefault(mc => mc.NominationId == finalComment.NominationId && mc.CriteriaId == finalComment.CriteriaId);
                        if (commentDb != null)
                        {
                            commentDb.AdminComment = finalComment.AdminComment;
                            commentDb.FinalScore   = finalComment.FinalScore;
                            _encourageDatabaseContext.Update(commentDb);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _logger.Log("Review-SaveFinalScore-POST-" + e.Message);
                throw;
            }


            return(Json(true));
        }
示例#2
0
        public ActionResult ConsolidatedNominations(ConsolidatedNominationsViewModel consolidatedNominationsViewModel)
        {
            var customDate            = _customDateService.GetCustomDate(consolidatedNominationsViewModel.AwardId);
            var awards                = _awardService.GetAllAwards();
            var currentAwardFrequency = consolidatedNominationsViewModel.AwardId > 0 ? GetAwardFrequency(consolidatedNominationsViewModel.AwardId).Data.ToString() : "";

            if (consolidatedNominationsViewModel.AwardId == 0)
            {
                consolidatedNominationsViewModel = new ConsolidatedNominationsViewModel();
                var award = awards.FirstOrDefault(a => a.Code == "SOM");
                if (award != null)
                {
                    customDate = _customDateService.GetCustomDate(award.Id);
                    consolidatedNominationsViewModel.AwardId    = award.Id;
                    consolidatedNominationsViewModel.AwardMonth = customDate.Month;
                    consolidatedNominationsViewModel.AwardYear  = customDate.Year;
                }
            }

            consolidatedNominationsViewModel.Criterias    = _encourageDatabaseContext.Query <Criteria>().Where(c => c.AwardId == consolidatedNominationsViewModel.AwardId).ToList();
            consolidatedNominationsViewModel.Reviewers    = new List <ReviewerViewModel>();
            consolidatedNominationsViewModel.Nominations  = new List <SubmittedNomination>();
            consolidatedNominationsViewModel.ListOfAwards = new SelectList(awards, "Id", "Name");
            List <UtilityUserRoles> activeReviewers;
            var utility = _commonDbContext.Query <Utility>().FirstOrDefault(r => r.Name == "Encourage");

            if (consolidatedNominationsViewModel.AwardMonth == customDate.Month && consolidatedNominationsViewModel.AwardYear == customDate.Year)
            {
                activeReviewers = _commonDbContext.Query <UtilityUserRoles>().Where(x => x.IsActive && x.UtilityId == utility.Id && x.RoleId == (int)Roles.Reviewer).ToList();
            }
            else
            {
                activeReviewers = _commonDbContext.Query <UtilityUserRoles>().Where(x => x.RoleId == (int)Roles.Reviewer && x.UtilityId == utility.Id).ToList();
            }


            foreach (var reviewer in activeReviewers)
            {
                var reviewerObj  = _commonDbContext.Query <User>().FirstOrDefault(u => u.ID == reviewer.UserId);
                var reviewerData = _encourageDatabaseContext.Query <Reviewer>().FirstOrDefault(x => x.UserId == reviewer.UserId);
                var reviewerId   = reviewerData != null ? reviewerData.Id : 0;
                consolidatedNominationsViewModel.Reviewers.Add(new ReviewerViewModel
                {
                    Id           = reviewerId,
                    UserId       = reviewer.UserId,
                    ReviewerName = reviewerObj != null ? reviewerObj.FirstName + " " + reviewerObj.LastName : ""
                });
            }
            var nominations = currentAwardFrequency == FrequencyCode.YEAR.ToString() ? _encourageDatabaseContext.Query <Nomination>().Include(a => a.ManagerComments).Include(b => b.ReviewerComments).Where(N => N.IsSubmitted == true && N.NominationDate.Value.Year == consolidatedNominationsViewModel.AwardYear && N.AwardId == consolidatedNominationsViewModel.AwardId).ToList() : _encourageDatabaseContext.Query <Nomination>().Include(a => a.ManagerComments).Include(b => b.ReviewerComments).Where(N => N.IsSubmitted == true && N.NominationDate.Value.Month == consolidatedNominationsViewModel.AwardMonth && N.NominationDate.Value.Year == consolidatedNominationsViewModel.AwardYear && N.AwardId == consolidatedNominationsViewModel.AwardId).ToList();

            foreach (var nomination in nominations)
            {
                var nominee           = _commonDbContext.Query <User>().FirstOrDefault(u => u.ID == nomination.UserId);
                var isWinner          = false;
                var checkResultStatus = _resultService.IsShortlistedOrWinner(nomination.Id);
                if (checkResultStatus == 1)
                {
                    isWinner = true;
                }
                var submittednomination = new SubmittedNomination
                {
                    NominationId           = nomination.Id,
                    UserName               = nominee != null ? nominee.FirstName + " " + nominee.LastName : "",
                    ManagerComments        = nomination.ManagerComments.ToList(),
                    ReviewerComments       = new List <ReviewerCommentViewModel>(),
                    IsWinner               = isWinner,
                    IsHistoricalNomination = IsHistoricalNomination(nomination)
                };

                submittednomination.IsShortListed = _encourageDatabaseContext.Query <Shortlist>().Any(s => s.NominationId == nomination.Id);

                foreach (var reviewerComment in nomination.ReviewerComments)
                {
                    var managerComment = nomination.ManagerComments.FirstOrDefault(m => m.CriteriaId == reviewerComment.CriteriaId);
                    var reviewComment  = new ReviewerCommentViewModel()
                    {
                        CriteriaId = reviewerComment.CriteriaId,
                        Comment    = reviewerComment.Comment,
                        Credit     = Convert.ToInt32(reviewerComment.Credit),
                        ReviewerId = reviewerComment.ReviewerId,
                        Weightage  = managerComment != null ? managerComment.Weightage : 0
                    };

                    submittednomination.ReviewerComments.Add(reviewComment);
                }
                consolidatedNominationsViewModel.Nominations.Add(submittednomination);
            }

            if (Request.IsAjaxRequest())
            {
                return(PartialView("_ConsolidatedNominationsPartialView", consolidatedNominationsViewModel));
            }
            else
            {
                consolidatedNominationsViewModel.CustomDate = customDate;
                return(View("ConsolidatedNominations", consolidatedNominationsViewModel));
            }
        }