public override void Execute() { foreach (var e in _evaluators) { if (e.Action == EvaluatorAction.Add) { if (_employeeEvaluation.UserName != e.UserName) { var employee = RavenSession .Query <Employee, EmployeeByUserName_Search>() .Where(x => x.UserName == e.UserName) .FirstOrDefault(); if (employee != null) { var evId = _employeeEvaluation.Id ?? EmployeeEvaluation.GenerateEvaluationId(_employeeEvaluation.Period, _employeeEvaluation.UserName); ExecuteCommand(new GenerateCalificationCommand(_employeeEvaluation.Period, _employeeEvaluation.UserName, e.UserName, _employeeEvaluation.TemplateId, CalificationType.Evaluator, evId)); } else { throw new ApplicationException(string.Format("Error: Evaluador no valido: {0}.", e.UserName)); } } } else { var id = EvaluationCalification.GenerateCalificationId(_employeeEvaluation.Period, _employeeEvaluation.UserName, e.UserName); var calification = RavenSession.Load <EvaluationCalification>(id); if (calification != null) { RavenSession.Delete(calification); } } } }
public override SharedLink ExecuteWithResult() { var evaluation = RavenSession.Load <EmployeeEvaluation>(EmployeeEvaluation.GenerateEvaluationId(_period, _userName)); if (evaluation == null) { throw new ApplicationException($"Could not find evaluation for period {_period} and user name {_userName}"); } if (evaluation.SharedLinks == null) { evaluation.SharedLinks = new SharedLinkList(); } //regular expression for strings that starts with "Link#" and followed only by numbers var regExp = new Regex(@"^Link#(\d+)$"); var lastLinkNumber = evaluation.SharedLinks .Select(x => x.FriendlyName) .Select(x => regExp.Match(x)) .Where(x => x.Success) .Select(x => int.Parse(x.Groups[1].Value)) .OrderBy(x => x) .LastOrDefault(); var newSharedLink = new SharedLink() { FriendlyName = $"Link#{lastLinkNumber + 1}", ExpirationDate = DateTime.Now.AddDays(3).ToUniversalTime(), SharedCode = GenerateSharedCode() }; evaluation.SharedLinks.Add(newSharedLink); RavenSession.SaveChanges(); return(newSharedLink); }
public override void Execute() { var evaluationId = EmployeeEvaluation.GenerateEvaluationId(_period, _evaluatedEmployee); var evaluation = RavenSession.Load <EmployeeEvaluation>(evaluationId); var califications = RavenSession.Advanced.LoadStartingWith <EvaluationCalification>(evaluationId + "/").ToList(); var isResponsibleEvalFinished = califications.Any(x => x.Owner == CalificationType.Responsible && x.Finished); var isCompanyEvalFinished = califications.Any(x => x.Owner == CalificationType.Company && x.Finished); var isAutoEvalFinished = califications.Any(x => x.Owner == CalificationType.Auto && x.Finished); var isEvaluatorEvalFinished = califications.Any(x => x.Owner == CalificationType.Evaluator && x.Finished); var action = RevertEvaluationActionsHelper.TryParse(_action); if (!RevertEvaluationActionsHelper.FindPosibleRevertAction( evaluation.Finished, evaluation.ReadyForDevolution, isCompanyEvalFinished, isResponsibleEvalFinished, isAutoEvalFinished, isEvaluatorEvalFinished, action)) { throw new ApplicationException("Action not allowed"); } var calificationsByType = califications.ToLookup(x => x.Owner); switch (action) { case RevertAction.ReopenForDevolution: evaluation.Finished = false; break; case RevertAction.CancelDevolution: evaluation.ReadyForDevolution = false; break; case RevertAction.ReopenEvalCompany: calificationsByType[CalificationType.Company].First().Finished = false; break; case RevertAction.ReopenEvalResponsible: calificationsByType[CalificationType.Responsible].First().Finished = false; RavenSession.Delete(calificationsByType[CalificationType.Company].First()); break; case RevertAction.ReopenAutoEvaluation: calificationsByType[CalificationType.Auto].First().Finished = false; break; case RevertAction.ReopenEvalEvaluators: foreach (var calification in calificationsByType[CalificationType.Evaluator]) { calification.Finished = false; } break; } }
public override void Execute() { var evaluation = RavenSession.Load <EmployeeEvaluation>(EmployeeEvaluation.GenerateEvaluationId(_period, _userName)); if (evaluation == null) { throw new ApplicationException($"Could not find evaluation for period {_period} and user name {_userName}"); } if (evaluation.SharedLinks == null || evaluation.SharedLinks.RemoveAll(x => x.SharedCode == _sharedLink.SharedCode) < 1) { throw new ApplicationException($"This evaluation does not contain a Shared link with code {_sharedLink.SharedCode}. Unable to delete"); } }
public override void Execute() { var evaluation = RavenSession.Load <EmployeeEvaluation>(EmployeeEvaluation.GenerateEvaluationId(_period, _userName)); if (evaluation == null) { throw new ApplicationException($"Could not find evaluation for period {_period} and user name {_userName}"); } var updatedLink = evaluation.SharedLinks.Where(x => x.SharedCode == _sharedLink.SharedCode).FirstOrDefault(); if (updatedLink == null) { throw new ApplicationException($"This evaluation does not contain a Shared link with code {_sharedLink.SharedCode}. Unable to update"); } updatedLink.FriendlyName = _sharedLink.FriendlyName; updatedLink.ExpirationDate = _sharedLink.ExpirationDate; }
public override CalificationsDto ExecuteWithResult() { var evId = EmployeeEvaluation.GenerateEvaluationId(_period, _evaluatedUser); var evaluation = RavenSession.Load <EmployeeEvaluation>(evId); var evaluationHelper = new EmployeeEvaluationHelper(RavenSession, _loggedUser); if (evaluation == null) { throw new ApplicationException(string.Format("Error: Evaluación inexistente: {0}.", evId)); } var isVisitor = (evaluation.SharedLinks == null ? false : evaluation.SharedLinks.Any(x => x.SharedCode == _sharedCode && x.ExpirationDate > DateTime.UtcNow)) || //has SharedCode (string.Compare(evaluationHelper.GetLastPeriodForResponisble(_evaluatedUser), _period) > 0); //is newer Responsible Employee_Search.Projection employee = RavenSession .Query <Employee_Search.Projection, Employee_Search>() .Where(x => x.IsActive && x.UserName == evaluation.UserName).FirstOrDefault(); var califications = RavenSession.Advanced.LoadStartingWith <EvaluationCalification>(evId + "/").ToList(); var evaluators = califications.Where(c => c.Owner == CalificationType.Evaluator).Select(c => c.EvaluatorEmployee).ToList(); var autoEvaluationDone = califications.Any(c => c.Owner == CalificationType.Auto && c.Finished); var responsibleEvaluationDone = califications.Any(c => c.Owner == CalificationType.Responsible && c.Finished); var companyEvaluationDone = califications.Any(c => c.Owner == CalificationType.Company && c.Finished); var state = EvaluationStateHelper.GetEvaluationState(autoEvaluationDone, responsibleEvaluationDone, companyEvaluationDone, evaluation.ReadyForDevolution, evaluation.Finished); var evaluationDto = CalificationsEvaluationDto.Create(evaluation, evaluators, evaluation.CurrentPosition ?? employee.CurrentPosition, evaluation.Seniority ?? employee.Seniority, companyEvaluationDone, state); if (!CanViewEvaluation(evaluationDto, califications, isVisitor)) { throw new ApplicationException(string.Format("Error: Usuario {0} no tiene permiso para ver la evaluación {1}", _loggedUser, evId)); } // If evaluation is finished // - Show ALWAYS company & auto if (evaluation.Finished) { return(GetFinishedEvaluation(evaluationDto, califications)); } // If loggedUser is the evaluated // - Show auto-eval if not RFD // - Show auto-eval & company if RFD if (_loggedUser == _evaluatedUser) { return(GetAutoEvaluation(evaluationDto, califications)); } // If loggedUser is responsible // - Show all if (_loggedUser == evaluationDto.ResponsibleId) { return(GetFullEvaluation(evaluationDto, califications)); } // If loggedUser is evaluator // - Show evluator eval return(GetEvaluatorEvaluation(evaluationDto, califications)); }
public override void Execute() { var evaluationId = EmployeeEvaluation.GenerateEvaluationId(_period, _evaluatedUserName); var evaluation = RavenSession.Load <EmployeeEvaluation>(evaluationId); if (evaluation == null) { throw new ApplicationException(string.Format("Error: Evaluación inexistente: {0}.", evaluationId)); } // Check that the new responsible exist var newResponsible = RavenSession .Query <Employee_Search.Projection, Employee_Search>() .Where(x => x.IsActive && x.UserName == _newResponsibleName).FirstOrDefault(); if (newResponsible == null) { throw new ApplicationException(string.Format("Error: Empleado inexistente: {0}.", _newResponsibleName)); } // Check that new responsible is not the evaluated employee if (evaluation.UserName == newResponsible.UserName) { throw new ApplicationException(string.Format("Error: {0} no puede ser responsable de su propia evaluación.", _newResponsibleName)); } // If the new responsible is the same as the old one, cancel the operation. if (evaluation.ResponsibleId == newResponsible.UserName) { throw new ApplicationException(string.Format("Error: {0} es actualmente el responsable de esta evaluación.", newResponsible.UserName)); } // The only moment when a user cant change an evaluation responsible, // is when the evaluation is complete and closed if (evaluation.Finished) { throw new ApplicationException(string.Format("Error: Esta evaluación ya está cerrada. No se puede modificar el responsable.")); } // Load evaluation califications var evaluationCalifications = RavenSession.Advanced.LoadStartingWith <EvaluationCalification>(evaluationId + "/").ToList(); var oldResponsibleCalification = evaluationCalifications.Where(x => x.Owner == CalificationType.Responsible).FirstOrDefault(); // Change the old responsible califications to an "Evaluator" calification type oldResponsibleCalification.Owner = CalificationType.Evaluator; // If the new responsible is an evaluator, make its calification as "Responsible" type var newResponsibleCalification = evaluationCalifications .Where(x => x.Owner == CalificationType.Evaluator && x.EvaluatorEmployee == newResponsible.UserName) .FirstOrDefault(); if (newResponsibleCalification != null) { newResponsibleCalification.Owner = CalificationType.Responsible; } // if not, create a new "Responsible" calification else { var newCalification = new EvaluationCalification { Owner = CalificationType.Responsible, Period = evaluation.Period, EvaluationId = evaluation.Id, EvaluatedEmployee = evaluation.UserName, EvaluatorEmployee = newResponsible.UserName, TemplateId = "Template/Default" }; RavenSession.Store(newCalification); } // Update responsible in the evaluation evaluation.ResponsibleId = newResponsible.UserName; RavenSession.SaveChanges(); }