Ejemplo n.º 1
0
        private PerformanceEvaluationSkill CreateOrRetrievePerformanceEvaluationSkill(ApplicationDbContext context, PerformanceEvaluation pe, Skill skill, string grade, string comment = null)
        {
            var performanceEvaluationSkill = context.PerformanceEvaluationsSkills.Where(x => x.PerformanceEvaluationId == pe.PerformanceEvaluationId).FirstOrDefault();

            if (performanceEvaluationSkill == null)
            {
                performanceEvaluationSkill = new PerformanceEvaluationSkill
                {
                    PerformanceEvaluation = pe,
                    Skill          = skill,
                    Grade          = grade,
                    PESkillComment = comment
                };
                context.PerformanceEvaluationsSkills.Add(performanceEvaluationSkill);
            }

            return(performanceEvaluationSkill);
        }
Ejemplo n.º 2
0
        //TO DO:Change or Remove
        public static PerformanceEvaluationSkill MapPerformanceEvaluationSkillModelToPerformanceEvaluationSkill(this PerformanceEvaluationSkillModel performanceEvaluationSkillModel)
        {
            if (performanceEvaluationSkillModel == null)
            {
                return(null);
            }

            var performanceEvaluationSkill = new PerformanceEvaluationSkill
            {
                Grade                   = performanceEvaluationSkillModel.Grade,
                PESkillComment          = performanceEvaluationSkillModel.Comment,
                SkillId                 = performanceEvaluationSkillModel.SkillId,
                Skill                   = performanceEvaluationSkillModel.Skill.MapSkillModelToSkill(),
                PerformanceEvaluationId = performanceEvaluationSkillModel.PerformanceEvaluationId,
                PerformanceEvaluation   = performanceEvaluationSkillModel.PerformanceEvaluation.MapPerformanceEvaluationModelToPerformanceEvaluation()
            };

            return(performanceEvaluationSkill);
        }
Ejemplo n.º 3
0
        public static PerformanceEvaluationSkillModel MapPerformanceEvaluationSkillToPerformanceEvaluationSkillModel(this PerformanceEvaluationSkill performanceEvaluationSkill)
        {
            if (performanceEvaluationSkill == null)
            {
                return(null);
            }

            var performanceEvaluationSkillModel = new PerformanceEvaluationSkillModel
            {
                Id      = performanceEvaluationSkill.PerformanceEvaluationSkillId,
                Grade   = performanceEvaluationSkill.Grade,
                Comment = performanceEvaluationSkill.PESkillComment,
                Skill   = performanceEvaluationSkill.Skill.MapSkillToSkillModel(),
                SkillId = performanceEvaluationSkill.SkillId,
                PerformanceEvaluationId = performanceEvaluationSkill.PerformanceEvaluationId
            };

            return(performanceEvaluationSkillModel);
        }
Ejemplo n.º 4
0
        public static void writePerformanceEvaluation(ApplicationUser reviewer)
        {
            Database.SetInitializer(new NullDatabaseInitializer <ApplicationDbContext>());
            using (ApplicationDbContext context = new ApplicationDbContext())
            {
                // mustDoPEs are not-submitted performance evaluations with end date 10 days before today
                var allOfMyPEs      = context.PerformanceEvaluations.Where(x => x.ReviewerId == reviewer.Id).ToList();
                var notSubmittedPEs = allOfMyPEs.Where(x => x.IsSubmitted == false).ToList();
                var mustDoPEs       = notSubmittedPEs.Where(x => x.EndDate.AddDays(-10) < DateTime.Now).ToList();

                if (mustDoPEs.Count != 0)
                {
                    Console.WriteLine("\n---------------------------------------------------------------------------------------------------");
                    Console.WriteLine("  id  |   First name   |   Last name   |         Start date          |        End date         ");
                    Console.WriteLine("---------------------------------------------------------------------------------------------------");
                    int id = 1;
                    foreach (var pe in mustDoPEs)
                    {
                        Console.WriteLine(id + "     |     " + pe.ConsultantFirstName + "     |     " + pe.ConsultantLastName + "     |     " + pe.StartDate + "     |     " + pe.EndDate);
                        id++;
                    }
                    Console.WriteLine("---------------------------------------------------------------------------------------------------");

                    int  option = 0;
                    bool isUserOrdinalNumberCorrect = false;

                    do
                    {
                        try
                        {
                            Console.Write("\nChoose the ordinal number of user you want to review (or type 0 to go back): ");
                            option = int.Parse(Console.ReadLine());
                            if (option >= 0 && option <= id)
                            {
                                isUserOrdinalNumberCorrect = true;
                            }
                        }
                        catch (Exception)
                        {
                            // if someone types a char that is not a number
                            Console.WriteLine("\nError! Type the correct ordinal number.");
                        }
                    } while (!isUserOrdinalNumberCorrect);

                    if (option == 0)
                    {
                        MenuOptions(reviewer);
                    }

                    // Get consultant's id from pe object and put it in the chosenPEUserId variable for further usage
                    string chosenPEConsultantId = mustDoPEs[option - 1].ConsultantId.ToString();
                    var    chosenConsultant     = context.Users.Include(x => x.JobTitle)
                                                  .Include(x => x.JobPosition)
                                                  .Include(x => x.Reviewer)
                                                  .Include("Template.TemplateDuration")
                                                  .Include("Template.Skills")
                                                  .Where(x => x.Id == chosenPEConsultantId).FirstOrDefault();

                    Console.WriteLine("\nEmployee Name: " + chosenConsultant.FirstName + " " + chosenConsultant.LastName);
                    Console.WriteLine("Job Title: " + chosenConsultant.JobTitle.Name);
                    Console.WriteLine("Review period: " + chosenConsultant.Template.TemplateDuration.Duration + " months");
                    Console.WriteLine("Reviewer Name: " + chosenConsultant.Reviewer.FirstName + " " + chosenConsultant.Reviewer.LastName);


                    var chosenPE = mustDoPEs[option - 1];
                    // Insert new, not submitted, performance evaluation for the same user with updated
                    // start and end dates
                    PerformanceEvaluation newPerformanceEvaluation = new PerformanceEvaluation
                    {
                        ConsultantId        = chosenConsultant.Id,
                        ConsultantFirstName = chosenConsultant.FirstName,
                        ConsultantLastName  = chosenConsultant.LastName,
                        ReviewerId          = chosenConsultant.Reviewer.Id,
                        ReviewerFirstName   = chosenConsultant.Reviewer.FirstName,
                        ReviewerLastName    = chosenConsultant.Reviewer.LastName,
                        JobTitle            = chosenConsultant.JobTitle,
                        JobPosition         = chosenConsultant.JobPosition,
                        StartDate           = chosenPE.EndDate,
                        EndDate             = chosenPE.EndDate.AddMonths(Convert.ToInt32(chosenConsultant.Template.TemplateDuration.Duration)),
                        IsSubmitted         = false,
                    };
                    context.PerformanceEvaluations.Add(newPerformanceEvaluation);
                    context.SaveChanges();


                    chosenPE.IsSubmitted   = true;
                    chosenPE.SubmittedDate = DateTime.Now;
                    context.SaveChanges();

                    if (chosenConsultant.Template.Skills != null)
                    {
                        foreach (var skill in chosenConsultant.Template.Skills)
                        {
                            bool   isCorrectGrade = false;
                            string grade          = "";
                            do
                            {
                                Console.WriteLine("\n" + skill.SkillName);
                                Console.Write("Type grade for the skill (E - Exceeds Expectations, M - Meets Expectations, N - Needs Improvement):");
                                grade = Console.ReadLine();
                                if (grade.ToUpper() == "E" || grade.ToUpper() == "M" || grade.ToUpper() == "N")
                                {
                                    isCorrectGrade = true;
                                }
                            } while (!isCorrectGrade);

                            PerformanceEvaluationSkill newPeSkill = new PerformanceEvaluationSkill()
                            {
                                PerformanceEvaluation = chosenPE,
                                Grade = grade,
                                Skill = skill
                            };

                            context.PerformanceEvaluationsSkills.Add(newPeSkill);
                            context.SaveChanges();
                        }
                    }

                    exitToMenuWithMessage(reviewer);
                }
                else
                {
                    exitToMenuWithMessage(reviewer, "\nNo active reviews!");
                }
            }
        }