Ejemplo n.º 1
0
        public bool EvaluationIsLastAverage(Adv.Domain.AdvCommission commission)
        {
            try
            {
                if (commission.Step != null)
                {
                    if (commission.Step.Type == Adv.StepType.economics)
                    {
                        try
                        {
                            Adv.Domain.AdvStep step = Manager.GetAll <Adv.Domain.AdvStep>(
                                st =>
                                st.Call != null && st.Call.Id == commission.Step.Call.Id &&
                                st.Type != Adv.StepType.economics
                                ).OrderByDescending(st => st.Order).FirstOrDefault();

                            return(step.EvalType == Adv.EvalType.Sum ? false : true);
                        }
                        catch
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(commission.Step.EvalType == Adv.EvalType.Sum ? false : true);
                    }
                }
            } catch { }

            return(false);
        }
Ejemplo n.º 2
0
        public bool EcoCreateEvaluation(long CommissionId)
        {
            if (!EcoEvalClear(CommissionId))
            {
                return(false);
            }


            Adv.Domain.AdvCommission comm = Manager.Get <Adv.Domain.AdvCommission>(CommissionId);

            if (
                comm.Step == null || comm.Step.Type != Adv.StepType.economics ||
                comm.Call == null)
            {
                return(false);
            }

            var stepsQuery = (from Adv.Domain.AdvStep step in Manager.GetIQ <Adv.Domain.AdvStep>()
                              where step.Type != Adv.StepType.economics &&
                              step.Call != null && step.Call.Id == comm.Call.Id
                              select step);

            Adv.Domain.AdvStep prevStep = stepsQuery.Where(s => s.Type == Adv.StepType.custom).OrderByDescending(s => s.Order).Skip(0).Take(1).FirstOrDefault();

            if (prevStep == null)
            {
                prevStep = stepsQuery.Where(s => s.Type == Adv.StepType.validation).Skip(0).Take(1).FirstOrDefault();
            }

            if (prevStep == null || prevStep.Status != Adv.StepStatus.Closed)
            {
                return(false);
            }

            IList <Adv.Domain.AdvSubmissionToStep> subStep = Manager.GetAll <Adv.Domain.AdvSubmissionToStep>(
                s => s.Step != null &&
                s.Step.Id == prevStep.Id &&
                s.Commission == null &&
                s.Admitted).OrderBy(s => s.Rank).ToList();

            IList <CpDomain.UserSubmission> AdmitSubmission = (from Adv.Domain.AdvSubmissionToStep sts in subStep
                                                               select sts.Submission).Distinct().ToList();

            IList <EcoD.EconomicEvaluation> ecEvaluations = Manager.GetAll <EcoD.EconomicEvaluation>(
                ecev => ecev.Call != null && ecev.Call.Id == comm.Call.Id &&
                ecev.Step != null && ecev.Step.Id == comm.Step.Id &&
                ecev.Commission != null && ecev.Commission.Id == comm.Id);

            if (ecEvaluations == null)
            {
                ecEvaluations = new List <EcoD.EconomicEvaluation>();
            }

            foreach (CpDomain.UserSubmission sub in AdmitSubmission)
            {
                EcoD.EconomicEvaluation ecEval = ecEvaluations.FirstOrDefault(ev => ev.Submission != null && ev.Submission.Id == sub.Id);
                bool isNew = false;
                if (ecEval == null)
                {
                    ecEval = new EcoD.EconomicEvaluation();
                    ecEval.CreateMetaInfo(GetCurrentPerson(), UC.IpAddress, UC.ProxyIpAddress);

                    ecEval.CurrentMember = null;
                    ecEval.Call          = comm.Call;
                    ecEval.Commission    = comm;
                    ecEval.Step          = comm.Step;
                    ecEval.Submission    = sub;
                    ecEval.CreateMetaInfo(GetCurrentPerson(), UC.IpAddress, UC.ProxyIpAddress);
                    isNew = true;
                }
                else
                {
                    ecEval.UpdateMetaInfo(GetCurrentPerson(), UC.IpAddress, UC.ProxyIpAddress);
                }

                ecEval.Status = AdvEconomic.EvalStatus.draft;


                ecEval.Tables = EcoTableFromSubmission(sub, ref ecEval);

                try
                {
                    ecEval.Rank          = subStep.FirstOrDefault(st => st.Submission != null && st.Submission.Id == sub.Id).Rank;
                    ecEval.AverageRating = Math.Round(subStep.FirstOrDefault(st => st.Submission != null && st.Submission.Id == sub.Id).AverageRating, 2);
                    ecEval.SumRating     = subStep.FirstOrDefault(st => st.Submission != null && st.Submission.Id == sub.Id).SumRating;
                } catch (Exception ex)
                {
                }


                if (isNew)
                {
                    ecEvaluations.Add(ecEval);
                }
            }

            if (!Manager.IsInTransaction())
            {
                Manager.BeginTransaction();
            }


            try
            {
                Manager.SaveOrUpdateList <EcoD.EconomicEvaluation>(ecEvaluations);
                Manager.Commit();
            } catch (Exception ex)
            {
                Manager.RollBack();
                return(false);
            }

            return(true);
        }