public override void Execute()
        {
            var evaluation = RavenSession.Load <EmployeeEvaluation>(_evaluationId);

            if (_loggedUser != evaluation.ResponsibleId)
            {
                throw new ApplicationException(string.Format("Error: Solo el responsable de la evaluación ({0}) puede iniciar su devolución", evaluation.ResponsibleId));
            }

            Employee_Search.Projection employee = RavenSession
                                                  .Query <Employee_Search.Projection, Employee_Search>()
                                                  .Where(x => x.IsActive && x.UserName == evaluation.UserName).FirstOrDefault();

            evaluation.ReadyForDevolution = true;
            evaluation.CurrentPosition    = employee.CurrentPosition;
            evaluation.Seniority          = employee.Seniority;

            RavenSession.Store(evaluation);
        }
        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));
        }