コード例 #1
0
        public ActionResult TakeEvaluation(TakeEvalViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            if (model.AllQuestions == null || model.AllQuestions.Count == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
            }

            var eval = UnitOfWork.EvaluationRepository.GetByID(model.EvalId);

            if (eval == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            if (model.RaterId == null) //Employee is taking the evaluation.
            {
                eval.SelfAnswers   = ConvertAnswersToString(model.AllQuestions);
                eval.CompletedDate = DateTime.Now;
                UnitOfWork.Save();
                if (eval.Raters.Count > 0)
                {
                    if (eval.Stage.StageName.Equals("Baseline"))
                    {
                        return(RedirectToAction("AssignRaters", "Raters", new { id = eval.EvaluationID }));
                    }
                    return(RedirectToAction("ConfirmRaters", "Raters", new { id = eval.EvaluationID }));
                }

                CheckCohortAndResetFlags(eval.Employee.CohortID);
                return(RedirectToAction("EmployeeEvalsIndex", new { id = eval.EmployeeID }));
            }

            // Rater is taking the evaluation
            var rater = UnitOfWork.RaterRepository.GetByID(model.RaterId);

            if (rater == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (!rater.Email.Equals(User.Identity.GetUserName()))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized));
            }

            rater.Answers = ConvertAnswersToString(model.AllQuestions);
            UnitOfWork.Save();
            CheckCohortAndResetFlags(eval.Employee.CohortID);
            return(RedirectToAction("RaterCleanup", "Raters", new { id = rater.RaterID }));
        }
コード例 #2
0
        //GET: Evaluations/TakeEvaluation/5
        public ActionResult TakeEvaluation(int?id, int?raterId, string code)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var eval = UnitOfWork.EvaluationRepository.GetByID(id);

            if (eval == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var employee = UnitOfWork.EmployeeRepository.GetByID(eval.EmployeeID);

            // If raterId is null, this is an employee taking their eval. Make sure the logged-in user is correct and hasn't already finished this eval.
            if (raterId == null)
            {
                if (employee == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
                if (!employee.Email.Equals(User.Identity.GetUserName()))
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized));
                }
                if (!string.IsNullOrEmpty(eval.SelfAnswers))
                {
                    TempData["EvalAlreadyComplete"] = "You have already completed this evaluation.";
                    return(RedirectToAction("EmployeeEvalsIndex", new { id = employee.EmployeeID }));
                }
                if (eval.OpenDate > DateTime.Today.Date)
                {
                    TempData["EvalNotYetOpen"] = "This evaluation is not open yet.";
                    return(RedirectToAction("EmployeeEvalsIndex", new { id = employee.EmployeeID }));
                }
                if (eval.CloseDate <= DateTime.Today.Date)
                {
                    TempData["EvalClosed"] = "This evaluation is closed.";
                    return(RedirectToAction("EmployeeEvalsIndex", new { id = employee.EmployeeID }));
                }
            }

            var model = new TakeEvalViewModel
            {
                AllQuestions = new List <QuestionViewModel>(),
                TypeId       = eval.TypeID,
                EvalId       = eval.EvaluationID,
                RaterId      = raterId
            };

            var count = 1;

            foreach (var category in eval.Type.Categories)
            {
                foreach (var question in category.Questions)
                {
                    model.AllQuestions.Add(new QuestionViewModel
                    {
                        Id       = count,
                        Text     = question.QuestionText,
                        Category = question.Category.Name
                    });
                    count++;
                }
            }

            if (raterId == null)
            {
                ViewBag.TakeEvalHeader = "Self-Evaluation for " + employee.FirstName + " " + employee.LastName + ".";
            }
            else
            {
                var rater = UnitOfWork.RaterRepository.GetByID(raterId);
                if (rater == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }

                ViewBag.TakeEvalHeader = "Evaluating " + eval.Employee.FirstName + " " + eval.Employee.LastName +
                                         " as a " + rater.Role + ".";
                ViewBag.TakeEvalSubHeader = "Logged in as " + rater.Name + ".";
            }

            return(View("TakeEvaluation", model));
        }