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);
                    }
                }
            }
        }
Example #2
0
        private void UpdateCalification(UpdateCalificationDto calification, EvaluationCalification storedCalification, bool finished)
        {
            // Update the calification comments and values
            storedCalification.Comments      = calification.Comments;
            storedCalification.Califications = calification.Items;
            storedCalification.Finished      = finished;

            // Update the EvaluationCalification document in the collection (DB)
            RavenSession.Store(storedCalification);
        }
        public override void Execute()
        {
            var calification = new EvaluationCalification()
            {
                Owner             = _owner,
                EvaluationId      = _evaluationId,
                Period            = _period,
                EvaluatedEmployee = _evaluated,
                EvaluatorEmployee = _evaluator,
                TemplateId        = _template
            };

            RavenSession.Store(calification);
        }
Example #4
0
        private bool CanUpdate(string loggedUser, EmployeeEvaluation evaluation, EvaluationCalification calification)
        {
            //Auto evaluator
            if (loggedUser == evaluation.UserName)
            {
                if (calification.Owner == CalificationType.Auto && calification.EvaluatorEmployee == loggedUser && !calification.Finished)
                {
                    return(true);
                }
            }

            //Responsible
            if (loggedUser == evaluation.ResponsibleId)
            {
                if (calification.Owner == CalificationType.Responsible && calification.EvaluatorEmployee == loggedUser && !calification.Finished)
                {
                    return(true);
                }

                // Auto calification can be edited (by the responsible) once finished (at the devolution)
                if (calification.Owner == CalificationType.Auto && evaluation.ReadyForDevolution)
                {
                    return(true);
                }

                // Company calification can be edited (by the responsible) once finished (at the devolution)
                if (calification.Owner == CalificationType.Company && calification.EvaluatorEmployee == COMPANY)
                {
                    return(true);
                }
            }

            //Evaluator
            if (calification.Owner == CalificationType.Evaluator && calification.EvaluatorEmployee == loggedUser && !calification.Finished)
            {
                return(true);
            }

            return(false);
        }
Example #5
0
 private void CreateCompanyEvaluation(EvaluationCalification storedCalification)
 {
     ExecuteCommand(new GenerateCalificationCommand(storedCalification.Period, storedCalification.EvaluatedEmployee, COMPANY, storedCalification.TemplateId, CalificationType.Company,
                                                    storedCalification.EvaluationId));
 }
        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();
        }