コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Title,Text,QualityGrade,InteractionGrade,HelpfulnessGrade,MentorGrade,TotalGrade,Points,Timestamp,AuthorID,ProfessorID")] ProfessorReview professorReview)
        {
            if (id != professorReview.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    professorReview.TotalGrade = calculateTotalGrade(professorReview);
                    _context.Update(professorReview);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProfessorReviewExists(professorReview.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Details", new { id = professorReview.ID }));
            }
            ViewData["AuthorID"]    = new SelectList(_context.User, "Id", "Id", professorReview.AuthorID);
            ViewData["ProfessorID"] = new SelectList(_context.Professor, "ID", "ID", professorReview.ProfessorID);
            return(View(professorReview));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("Title,Text,QualityGrade,InteractionGrade,HelpfulnessGrade,MentorGrade,Points,AuthorID,ProfessorID")] ProfessorReview professorReview, ICollection <int> tags)
        {
            if (professorReview.MentorGrade == 0)
            {
                professorReview.MentorGrade = null;
            }
            professorReview.TotalGrade = calculateTotalGrade(professorReview);
            professorReview.Timestamp  = DateTime.Now;
            List <ProfessorReviewTagSet> tagSet = new List <ProfessorReviewTagSet>();

            foreach (var tagId in tags)
            {
                var temp = new ProfessorReviewTagSet();
                temp.ProfessorReviewID    = professorReview.ID;
                temp.ProfessorReviewTagID = tagId;
                tagSet.Add(temp);
            }

            professorReview.ProfessorReviewTagSet = tagSet;

            if (ModelState.IsValid)
            {
                _context.Add(professorReview);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Details", new { id = professorReview.ID }));
            }
            ViewData["AuthorID"]      = professorReview.AuthorID;
            ViewData["ProfessorID"]   = professorReview.ProfessorID;
            ViewData["ProfessorTags"] = new SelectList(_context.ProfessorReviewTag, "ID", "Name");
            return(View());
        }
コード例 #3
0
        private decimal calculateTotalGrade(ProfessorReview pr)
        {
            int     sum    = 0;
            decimal result = 0;

            sum += pr.HelpfulnessGrade;
            sum += pr.InteractionGrade;
            sum += pr.QualityGrade;

            if (pr.MentorGrade.HasValue)
            {
                sum   += pr.MentorGrade.Value;
                result = sum / (decimal)4;
            }
            else
            {
                result = sum / (decimal)3;
            }

            return(result);
        }