public static PerformanceEvaluationModel MapPerformanceEvaluationToPerformanceEvaluationModel(this PerformanceEvaluation performanceEvaluation, bool mapConsultant, bool mapJobTitle = true, bool mapJobPosition = true, bool mapTemplate = true) { if (performanceEvaluation == null) { return(null); } var performanceEvaluationModel = new PerformanceEvaluationModel { Id = performanceEvaluation.PerformanceEvaluationId, ConsultantId = performanceEvaluation.ConsultantId, ConsultantFirstName = performanceEvaluation.ConsultantFirstName, ConsultantLastName = performanceEvaluation.ConsultantLastName, ConsultantJobTitleId = performanceEvaluation.JobTitleId, ConsultantJobPositionId = performanceEvaluation.JobPositionId, ReviewerId = performanceEvaluation.ReviewerId, ReviewerFirstName = performanceEvaluation.ReviewerFirstName, ReviewerLastName = performanceEvaluation.ReviewerLastName, StartDate = performanceEvaluation.StartDate, EndDate = performanceEvaluation.EndDate, IsSubmited = performanceEvaluation.IsSubmitted, SubmitedDate = performanceEvaluation.SubmittedDate, ConsultantComment = performanceEvaluation.ConsultantComment, SignedOnDate = performanceEvaluation.SignedOnDateByConsultant, TemplateId = performanceEvaluation.TemplateId }; if (mapJobPosition) { performanceEvaluationModel.ConsultantJobPosition = performanceEvaluation.JobPosition.MapJobPositionToJobPositionModel(); } if (mapJobTitle) { performanceEvaluationModel.ConsultantJobTitle = performanceEvaluation.JobTitle.MapJobTitleToJobTitleModel(); } if (mapTemplate) { performanceEvaluationModel.Template = performanceEvaluation.Template.MapTemplateToTemplateModel(true); } if (performanceEvaluation.PerformanceEvaluationSkills != null) { performanceEvaluationModel.PerformanceEvaluationSkills = performanceEvaluation.PerformanceEvaluationSkills .Select(x => x.MapPerformanceEvaluationSkillToPerformanceEvaluationSkillModel()).ToList(); } if (mapConsultant) { performanceEvaluationModel.Consultant = performanceEvaluation.Consultant.MapApplicationUserToApplicationUserModel(); } return(performanceEvaluationModel); }
public bool AcknowledgePerformanceEvaluation(PerformanceEvaluationModel performanceEvaluationModel) { if (String.IsNullOrEmpty(performanceEvaluationModel.ConsultantComment)) { throw new ArgumentException("Comment must be written!"); } var performanceEvaluation = _context.PerformanceEvaluations .Where(x => x.PerformanceEvaluationId == performanceEvaluationModel.Id) .FirstOrDefault(); performanceEvaluation.ConsultantComment = performanceEvaluationModel.ConsultantComment; performanceEvaluation.SignedOnDateByConsultant = DateTime.Now; return(_context.SaveChanges() > 0); }
public IHttpActionResult SubmitPerformanceEvaluation([FromBody] PerformanceEvaluationModel performanceEvaluationModel) { var performanceEvaluations = _performanceEvaluationService.SaveOrSubmitPerformanceEvaluation(performanceEvaluationModel, true); NotificationModel notification = new NotificationModel(); notification.PeId = performanceEvaluations.Id; notification.ReceiverId = performanceEvaluations.ReviewerId; notification.ReceiverUserName = performanceEvaluations.Consultant.Username; notification.Sender = performanceEvaluations.ReviewerFirstName + " " + performanceEvaluations.ReviewerLastName; notification.Seen = false; notification.Message = "You have review to acknowledge submited by "; var created_notif = _notificationService.CreateNotification(notification); _context.Clients.Group(created_notif.ReceiverUserName).displayNotificationConsultant(created_notif); return(Ok(performanceEvaluations)); }
public static bool IsValid(this PerformanceEvaluationModel peModel, out List <string> errorMessages, bool submit = false) { errorMessages = new List <string>(); if (peModel == null) { errorMessages.Add("PerformanceEvaluationModel cannot be null."); return(false); } if (peModel.ConsultantJobTitleId == 0) { errorMessages.Add("User must have a job title."); } if (peModel.ConsultantJobPositionId == 0) { errorMessages.Add("User must have a job position."); } if (peModel.StartDate == null) { errorMessages.Add("Performance evaluation model must have start date defined."); } if (peModel.EndDate == null) { errorMessages.Add("Performance evaluation model must have end date defined."); } if (peModel.IsSubmited) { errorMessages.Add("Cannot edit submited performance evaluation."); } // Performance Evaluation Skills validation foreach (var peSkillModel in peModel.PerformanceEvaluationSkills) { if (peSkillModel.PerformanceEvaluationId == 0) { errorMessages.Add("Performance evaluation skill model must be part of Performance evaluation"); } if (peSkillModel.SkillId == 0) { errorMessages.Add("Performance evaluation skill model must have skill id defined."); } List <string> correctGrades = new List <string>(new string[] { "E", "M", "N" }); if (peSkillModel.Grade != null) { if (!correctGrades.Any(item => peSkillModel.Grade.Contains(item))) { errorMessages.Add("Performance evaluation skill model grades must have values 'E', 'M' or 'N'."); } } if (submit) { if (String.IsNullOrWhiteSpace(peSkillModel.Comment)) { errorMessages.Add("Performance evaluation skill model must have comment defined before submit."); } if (String.IsNullOrWhiteSpace(peSkillModel.Grade)) { errorMessages.Add("Performance evaluation skill model must have grade defined before submit."); } } } return(errorMessages.Count == 0); }
public PerformanceEvaluationModel SaveOrSubmitPerformanceEvaluation(PerformanceEvaluationModel performanceEvaluationModel, bool isSubmit = false) { List <string> errorMessage = null; if (!performanceEvaluationModel.IsValid(out errorMessage, isSubmit)) { throw new ArgumentException("performanceEvaluationModel", String.Join("; ", errorMessage)); } var performanceEvaluationSkillsOfExistingPerformanceEvaluation = _context.PerformanceEvaluationsSkills .Include(x => x.Skill) .Where(x => x.PerformanceEvaluationId == performanceEvaluationModel.Id) .ToList(); foreach (var peSkill in performanceEvaluationModel.PerformanceEvaluationSkills) { var peSkillId = peSkill.SkillId; if (performanceEvaluationSkillsOfExistingPerformanceEvaluation .Any(x => x.SkillId == peSkillId)) { var peSkillOfExistingPe = performanceEvaluationSkillsOfExistingPerformanceEvaluation .Where(x => x.SkillId == peSkill.SkillId) .FirstOrDefault(); if (peSkill.Grade != null && peSkillOfExistingPe.Grade != peSkill.Grade) { peSkillOfExistingPe.Grade = peSkill.Grade; } if (peSkill.Comment != null && peSkillOfExistingPe.PESkillComment != peSkill.Comment) { peSkillOfExistingPe.PESkillComment = peSkill.Comment; } } else { if (peSkill.Grade != null || peSkill.Comment != null) { // Add new entry in PerformanceEvaluationSkill table if reviewer wrote a comment or a grade var performanceEvaluationSkillModel = new PerformanceEvaluationSkillModel { PerformanceEvaluationId = performanceEvaluationModel.Id, SkillId = peSkill.SkillId, Grade = peSkill.Grade, Comment = peSkill.Comment }; var performanceEvaluationSkill = performanceEvaluationSkillModel .MapPerformanceEvaluationSkillModelToPerformanceEvaluationSkill(); _context.PerformanceEvaluationsSkills.Add(performanceEvaluationSkill); _context.SaveChanges(); performanceEvaluationSkillModel.Id = performanceEvaluationSkill.PerformanceEvaluationId; } } } //Include users and return performance evaluation var performanceEvaluation = _context.PerformanceEvaluations .Include(x => x.Consultant) .Include(x => x.Reviewer) .Where(x => x.PerformanceEvaluationId == performanceEvaluationModel.Id) .FirstOrDefault(); if (isSubmit) { performanceEvaluation.IsSubmitted = true; performanceEvaluation.SubmittedDate = DateTime.Now; _context.SaveChanges(); } return(performanceEvaluation.MapPerformanceEvaluationToPerformanceEvaluationModel(true)); }
public IHttpActionResult AcknowledgePerformanceEvaluation([FromBody] PerformanceEvaluationModel peModel) { var performanceEvaluations = _performanceEvaluationService.AcknowledgePerformanceEvaluation(peModel); return(Ok(performanceEvaluations)); }
public IHttpActionResult SavePerformanceEvaluation([FromBody] PerformanceEvaluationModel performanceEvaluationModel) { var performanceEvaluations = _performanceEvaluationService.SaveOrSubmitPerformanceEvaluation(performanceEvaluationModel); return(Ok(performanceEvaluations)); }
public static PerformanceEvaluation MapPerformanceEvaluationModelToPerformanceEvaluation(this PerformanceEvaluationModel peModel) { if (peModel == null) { return(null); } var performanceEvaluation = new PerformanceEvaluation { PerformanceEvaluationId = peModel.Id, Consultant = peModel.Consultant.MapApplicationUserModelToApplicationUser(), ConsultantId = peModel.ConsultantId, ConsultantFirstName = peModel.ConsultantFirstName, ConsultantLastName = peModel.ConsultantLastName, JobTitleId = peModel.ConsultantJobTitleId, JobPositionId = peModel.ConsultantJobPositionId, Reviewer = peModel.Reviewer.MapApplicationUserModelToApplicationUser(), ReviewerId = peModel.ReviewerId, ReviewerFirstName = peModel.ReviewerFirstName, ReviewerLastName = peModel.ReviewerLastName, StartDate = peModel.StartDate, EndDate = peModel.EndDate, IsSubmitted = peModel.IsSubmited, SubmittedDate = peModel.SubmitedDate, TemplateId = peModel.TemplateId, //PerformanceEvaluationSkills = peModel.PerformanceEvaluationSkills // .Select(x => x.MapPerformanceEvaluationSkillModelToPerformanceEvaluationSkill()) // .ToList() }; return(performanceEvaluation); }