Example #1
0
        public void UpdateEvaluation(Evaluation evaluation)
        {
            ServiceErrorHandler.Handle(() =>
            {
                Log.Info(string.Format("Attempting to update evaluation with ID {0}", evaluation.Id));
                var dao = this.evaluationDaoBuilder.Create();
                var id  = evaluation.Id;

                if (!dao.EvaluationExists(id))
                {
                    throw new ItemNotFoundServiceException($"Unable to find an evaluation with id {id}");
                }

                if (evaluation.CreationDate != null)
                {
                    throw new InvalidItemServiceException("Bad arguments, cannot update existing evaluation Creation Date");
                }
                else if (evaluation.EditDate != null)
                {
                    throw new InvalidItemServiceException("Bad arguments, cannot update existing evaluation Edit Date");
                }

                evaluation.EditDate = DateTime.Now.ToUniversalTime();
                dao.UpdateEvaluation(evaluation);
            });
        }
Example #2
0
        public EvaluationScore CreateAnswers(Guid idEvaluation, EvaluationAnswer answersList)
        {
            return(ServiceErrorHandler.Handle(() =>
            {
                Log.Info($"Checking if evaluation with id {idEvaluation} exists");
                var answersDao = this.answersDaoBuilder.Create();
                var evaluationsDao = this.evaluationsDaoBuilder.Create();
                var templatesDao = this.templatesDaoBuilder.Create();

                if (!evaluationsDao.EvaluationExists(idEvaluation))
                {
                    throw new ItemNotFoundServiceException($"Unable to find an evaluation with id {idEvaluation}");
                }

                var evaluation = evaluationsDao.GetEvaluation(idEvaluation);
                var template = templatesDao.GetTemplate(evaluation.IdTemplate);
                var evaluationTemplate = EvaluationScoreHelpers.GenerateEvaluationTemplate(template, evaluation);
                evaluationTemplate.AppendAnswers(answersList);
                var scoreService = ServicesFacade.Instance.GetScoreService();
                var caluculatedEvaluation = scoreService.CalculateScore(evaluationTemplate);

                Log.Info($"Creating answers for evaluation {idEvaluation}");
                caluculatedEvaluation.IdEvaluation = idEvaluation;
                caluculatedEvaluation.Date = DateTime.Now.ToUniversalTime();
                EvaluationScore newAnswers = answersDao.CreateAnswers(caluculatedEvaluation);

                Log.Info($"Evaluation answers created succesfully, Id {newAnswers.Id}");
                return newAnswers;
            }));
        }
Example #3
0
 public PaginatedList <Evaluation> GetEvaluations(QueryParameters queryParameters)
 {
     return(ServiceErrorHandler.Handle(() =>
     {
         Log.Info("Getting the paginated evaluations");
         var dao = this.evaluationDaoBuilder.Create();
         return dao.GetEvaluations(queryParameters);
     }));
 }
Example #4
0
 public IList <Evaluation> GetEvaluations()
 {
     return(ServiceErrorHandler.Handle(() =>
     {
         Log.Info("Getting the evaluations");
         var dao = this.evaluationDaoBuilder.Create();
         return dao.GetEvaluations();
     }));
 }
Example #5
0
 public void UpdateTemplate(Template template)
 {
     ServiceErrorHandler.Handle(() =>
     {
         Log.Info(string.Format("Attemping to update template with ID {0}", template.Id));
         var dao = this.templateDaoBuilder.Create();
         dao.UpdateTemplate(template);
     });
 }
Example #6
0
 public void DeleteTemplate(Guid id)
 {
     ServiceErrorHandler.Handle(() =>
     {
         Log.Info(string.Format("Attempting to delete Template with ID: {0}", id));
         var dao = this.templateDaoBuilder.Create();
         dao.DeleteTemplate(id);
     });
 }
Example #7
0
 public EvaluationScore CalculateScore(EvaluationScore evaluationScore)
 {
     return(ServiceErrorHandler.Handle(() =>
     {
         var calculator = new MathParserCalculator(evaluationScore);
         var calculated = calculator.Calculate();
         this.CalculateQualification(calculated);
         return calculated;
     }));
 }
Example #8
0
 public Template GetTemplate(Guid id)
 {
     return(ServiceErrorHandler.Handle(() =>
     {
         var dao = this.templateDaoBuilder.Create();
         var template = dao.GetTemplate(id);
         Log.Info(string.Format("Template found with id: {0}", template.Id));
         return template;
     }));
 }
Example #9
0
 public IList <Template> GetTemplates()
 {
     return(ServiceErrorHandler.Handle(() =>
     {
         var dao = this.templateDaoBuilder.Create();
         var templatelist = dao.GetTemplates();
         Log.Info(string.Format("Found {0} templates", templatelist.Count));
         return templatelist;
     }));
 }
Example #10
0
 public IList <EvaluationScore> GetAnswers(Guid idEvaluation)
 {
     return(ServiceErrorHandler.Handle(() =>
     {
         Log.Info(string.Format("Getting the list of answers for the evaluation with ID {0}", idEvaluation));
         var dao = this.answersDaoBuilder.Create();
         IList <EvaluationScore> evaluationAnswers = dao.GetAnswers(idEvaluation);
         Log.Info(string.Format("List of answers for evaluation : {0}", evaluationAnswers));
         return evaluationAnswers;
     }));
 }
Example #11
0
        public Template CreateTemplate(Template template)
        {
            return(ServiceErrorHandler.Handle(() =>
            {
                Log.Info("Creating the Template");
                ITemplatesDao dao = this.templateDaoBuilder.Create();
                Template newTemplate = dao.CreateTemplate(template);

                return newTemplate;
            }));
        }
Example #12
0
        public void DeleteEvaluation(Guid id)
        {
            ServiceErrorHandler.Handle(() =>
            {
                Log.Info(string.Format("Attemping to delete Evaluation with ID {0}", id));
                var dao = this.evaluationDaoBuilder.Create();

                if (!dao.EvaluationExists(id))
                {
                    throw new ItemNotFoundServiceException($"Unable to find an evaluation with id {id}");
                }

                dao.DeleteEvaluation(id);
            });
        }
Example #13
0
        public Evaluation GetEvaluation(Guid id)
        {
            return(ServiceErrorHandler.Handle(() =>
            {
                Log.Info(string.Format("Getting the evaluation with ID {0}", id));
                var dao = this.evaluationDaoBuilder.Create();
                if (!dao.EvaluationExists(id))
                {
                    throw new ItemNotFoundServiceException($"Unable to find an evaluation with id {id}");
                }

                var evaluation = dao.GetEvaluation(id);
                Log.Info(string.Format("Evaluation: {0}", evaluation));
                return evaluation;
            }));
        }
Example #14
0
        public EvaluationScore GetAnswer(Guid idAnswer)
        {
            return(ServiceErrorHandler.Handle(() =>
            {
                Log.Info($"Getting answers with ID {idAnswer}");
                var dao = this.answersDaoBuilder.Create();
                if (!dao.AnswersExist(idAnswer))
                {
                    throw new ItemNotFoundServiceException($"Unable to find answers with id {idAnswer}");
                }

                var evaluationAnswers = dao.GetAnswer(idAnswer);
                Log.Info($"Answers with ID {evaluationAnswers.Id} retrieved");
                return evaluationAnswers;
            }));
        }
Example #15
0
        public ApplicationHealthInfo GetServiceHealth()
        {
            return(ServiceErrorHandler.Handle(() =>
            {
                Log.Info("Getting the application health information");
                var dao = this.appInfoDaoBuilder.CreateFromFile(ApplicationInfoFile);
                var appInfo = dao.GetAppInfo();

                var info = new ApplicationHealthInfo()
                {
                    Application = appInfo,
                    Status = ApplicationHealthStatus.Up
                };

                Log.Info(string.Format("ApplicationHealthInfo: {0}", info));
                return info;
            }));
        }
Example #16
0
        public Evaluation CreateEvaluation(Evaluation evaluation)
        {
            return(ServiceErrorHandler.Handle(() =>
            {
                Log.Info("Creating the Evaluation");
                IEvaluationsDao dao = this.evaluationDaoBuilder.Create();

                evaluation.CreationDate = DateTime.Now.ToUniversalTime();
                evaluation.EditDate = DateTime.Now.ToUniversalTime();

                var template = ServicesFacade.Instance.GetTemplatesService().GetTemplate(evaluation.IdTemplate);

                EvaluationValidator.Validate(evaluation, template);

                Evaluation newEvaluation = dao.CreateEvaluation(evaluation);

                Log.Info($"Evaluation Created Succesfully, Id {newEvaluation.Id}");
                return newEvaluation;
            }));
        }