public static bool IsInfoValid(this PerformanceEvaluationInfoModel peInfoModel, out List <string> errorMessages) { errorMessages = new List <string>(); if (peInfoModel == null) { errorMessages.Add("Performance evaluation info model cannot be null"); return(false); } if (peInfoModel.ConsultantJobTitleId == 0) { errorMessages.Add("User must have a job title."); } if (peInfoModel.ConsultantJobPositionId == 0) { errorMessages.Add("User must have a job position."); } if (peInfoModel.StartDate == null) { errorMessages.Add("Performance evaluation model must have start date defined."); } if (peInfoModel.DueDate == null) { errorMessages.Add("Performance evaluation model must have end date defined."); } return(errorMessages.Count == 0); }
public static PerformanceEvaluationInfoModel MapApplicationUserToPerformanceEvaluationInfoModel(this ApplicationUser user, DateTime startDate, DateTime endDate) { if (user == null) { return(null); } var performanceEvaluationInfoModel = new PerformanceEvaluationInfoModel { ConsultantId = user.Id, ConsultantFirstName = user.FirstName, ConsultantLastName = user.LastName, ConsultantJobTitleId = user.JobTitleId, ConsultantJobTitle = user.JobTitle.MapJobTitleToJobTitleModel(), ConsultantJobPositionId = user.JobPositionId, ConsultantJobPosition = user.JobPosition.MapJobPositionToJobPositionModel(), ReviewerId = user.ReviewerId, ReviewerFirstName = user.Reviewer.FirstName, ReviewerLastName = user.Reviewer.LastName, TemplateId = user.TemplateId, Template = user.Template.MapTemplateToTemplateModel(true), StartDate = startDate, DueDate = endDate, }; return(performanceEvaluationInfoModel); }
public static PerformanceEvaluationInfoModel MapPerformanceEvaluationToPerformanceEvaluationInfoModel(this PerformanceEvaluation performanceEvaluation) { var performanceEvaluationInfoModel = new PerformanceEvaluationInfoModel { Id = performanceEvaluation.PerformanceEvaluationId, ConsultantId = performanceEvaluation.ConsultantId, ConsultantFirstName = performanceEvaluation.Consultant.FirstName, ConsultantLastName = performanceEvaluation.Consultant.LastName, ConsultantJobTitleId = performanceEvaluation.Consultant.JobTitleId, ConsultantJobTitle = performanceEvaluation.Consultant.JobTitle.MapJobTitleToJobTitleModel(), ConsultantJobPositionId = performanceEvaluation.Consultant.JobPositionId, ConsultantJobPosition = performanceEvaluation.Consultant.JobPosition.MapJobPositionToJobPositionModel(), ReviewerId = performanceEvaluation.ReviewerId, ReviewerFirstName = performanceEvaluation.Reviewer.FirstName, ReviewerLastName = performanceEvaluation.Reviewer.LastName, TemplateId = performanceEvaluation.TemplateId, Template = performanceEvaluation.Template.MapTemplateToTemplateModel(true), StartDate = performanceEvaluation.StartDate, DueDate = performanceEvaluation.EndDate }; return(performanceEvaluationInfoModel); }
public ICollection <PerformanceEvaluationInfoModel> GetPerformanceEvaluationsForReviewer(string reviewerId) { if (String.IsNullOrWhiteSpace(reviewerId)) { throw new ArgumentOutOfRangeException("reviewerId", "Reviewer's id can't be null."); } // Each time reviewer, with id of reviewerId, logs into the system, // performance evaluations of his reviewees are collected from database; // There are three cases: // - Reviewee's performance evaluation is in 'Edit' phase (performance evaluation has already been created, but not submitted) // - Reviewee's performance evaluation has not been created yet, but it's not his first performance evaluation // - Reviewee's never had a performance evaluation // All of these cases are implemented below var usersIReview = _context.Users.Include(x => x.JobPosition) .Include(x => x.JobTitle) .Include(x => x.Template) .Include("Template.Skills") .Include("Template.TemplateDuration") .Include(x => x.Reviewer) .Where(x => x.Reviewer.Id == reviewerId) .ToList(); List <PerformanceEvaluationInfoModel> performanceEvaluationsForReviewer = new List <PerformanceEvaluationInfoModel>(); foreach (var user in usersIReview) { var latestPerformanceEvaluation = _context.PerformanceEvaluations.Include(x => x.JobPosition) .Include(x => x.JobTitle) .Include(x => x.Template) .Include("Template.Skills") .Where(x => x.ConsultantId == user.Id) .Where(x => x.ReviewerId == reviewerId) .ToList() .OrderByDescending(x => x.EndDate.Date) .ThenBy(x => x.EndDate.TimeOfDay) .FirstOrDefault(); var performanceEvaluationInfoModel = new PerformanceEvaluationInfoModel(); var startDate = DateTime.MinValue; var endDate = DateTime.MinValue; if (latestPerformanceEvaluation != null) { // If performance evaluation for the user has been already created, but it hasn't been submitted yet // (user's performanceEvaluation exists in the database, with property ISubmitted = false) if (!latestPerformanceEvaluation.IsSubmitted) { performanceEvaluationInfoModel = latestPerformanceEvaluation.MapPerformanceEvaluationToPerformanceEvaluationInfoModel(); startDate = latestPerformanceEvaluation.StartDate; endDate = latestPerformanceEvaluation.EndDate; performanceEvaluationInfoModel.InEditStage = true; } else if (latestPerformanceEvaluation.IsSubmitted) { // If user has had performance evaluation before, a new peInfoModel is created // with START DATE of his latest submitted and signed pe's END DATE; // END DATE value, of the new peInfoModel, is then set to sum of START DATE and TEMPLATE DURATION startDate = latestPerformanceEvaluation.EndDate; endDate = startDate.AddMonths(user.Template.TemplateDuration.Duration); performanceEvaluationInfoModel = user.MapApplicationUserToPerformanceEvaluationInfoModel(startDate, endDate); performanceEvaluationInfoModel.InCreateStage = true; } } else { // If user has never had a performance evaluation, a new peInfoModel is created // START DATE is set to user's EMPLOYMENT DATE // END DATE is set to sum of user's EMPLOYMENT DATE and TEMPLATE DURATION startDate = user.EmploymentDate; endDate = startDate.AddMonths(user.Template.TemplateDuration.Duration); performanceEvaluationInfoModel = user.MapApplicationUserToPerformanceEvaluationInfoModel(startDate, endDate); performanceEvaluationInfoModel.InCreateStage = true; } if (DateTime.Now > endDate) { performanceEvaluationInfoModel.IsLate = true; } else if (endDate.Subtract(DateTime.Now).TotalDays <= 10) { performanceEvaluationInfoModel.IsNearDueDate = true; } performanceEvaluationsForReviewer.Add(performanceEvaluationInfoModel); } return(performanceEvaluationsForReviewer .OrderByDescending(x => x.DueDate.Date) .ThenBy(x => x.DueDate.TimeOfDay) .ToList()); }
public static PerformanceEvaluation MapPerformanceEvaluationInfoModelToPerformanceEvaluation(this PerformanceEvaluationInfoModel peInfoModel, bool mapTemplate = true, bool mapJobTitle = true, bool mapJobPosition = true) { if (peInfoModel == null) { return(null); } PerformanceEvaluation pe = new PerformanceEvaluation { PerformanceEvaluationId = peInfoModel.Id, ConsultantId = peInfoModel.ConsultantId, ConsultantFirstName = peInfoModel.ConsultantFirstName, ConsultantLastName = peInfoModel.ConsultantLastName, JobTitleId = peInfoModel.ConsultantJobTitleId, JobPositionId = peInfoModel.ConsultantJobPositionId, ReviewerId = peInfoModel.ReviewerId, ReviewerFirstName = peInfoModel.ReviewerFirstName, ReviewerLastName = peInfoModel.ReviewerLastName, StartDate = peInfoModel.StartDate, EndDate = peInfoModel.DueDate, TemplateId = peInfoModel.TemplateId }; if (mapTemplate) { pe.Template = peInfoModel.Template.MapTemplateModelToTemplate(); } if (mapJobTitle) { pe.JobTitle = peInfoModel.ConsultantJobTitle.MapJobTitleModelToJobTitle(); } if (mapJobPosition) { pe.JobPosition = peInfoModel.ConsultantJobPosition.MapJobPositionModelToJobPosition(); } return(pe); }