コード例 #1
0
        private GenericOperationResult <IEnumerable <Quiz> > GetPredefinedQuizes(User student)
        {
            GenericOperationResult <IEnumerable <Quiz> > result =
                OperationResult.GetGenericResultObject <IEnumerable <Quiz> >();

            try
            {
                // get all the tests information that  the student has taken
                var quizesStudentHasTaken = _studentQuizResultRepository.GetAllItems().ToList().Where(x => x.StudentId.Equals(student.UserID));

                //get all the quizes
                var allQuizes = _quizRepository.GetAllItems().Where(x => x.IsRandom == null || x.IsRandom == false);

                //filter only non taken quizes
                var takenQuizesIds = quizesStudentHasTaken.Select(x => x.QuizId).ToList();

                var filteredQuizes = (from quiz in allQuizes let quizId = quiz.Id where !takenQuizesIds.Contains(quizId) select quiz).ToList();

                //if everything goes well
                result.SetData(filteredQuizes);
                result.SetSuccess();
                return(result);
            }
            catch (Exception e)
            {
                result.SetException();
                result.AddExceptionMessage(e.Message);
            }

            return(result);
        }
コード例 #2
0
        public bool CreateItem <T>(T item, ICrudRepository <T> repository, GenericOperationResult <T> or) where T : class, new()
        {
            if (item == null)
            {
                or.AddMessage(_localizedMessagesService.GetErrorMessage(ErrorMessageKeys.NullObjectReference));
                or.SetFail();
                return(false);
            }

            try
            {
                var success = repository.CreateItem(item);

                if (success)
                {
                    or.SetData(item);
                    return(true);
                }
                else
                {
                    or.AddMessage(_localizedMessagesService.GetErrorMessage(ErrorMessageKeys.RepositoryError));
                    return(false);
                }
            }
            catch (Exception e)
            {
                or.AddMessage(_localizedMessagesService.GetErrorMessage(ErrorMessageKeys.RepositoryError));
                return(false);
            }
        }
コード例 #3
0
 public bool GetItems <T>(ICrudRepository <T> repository, GenericOperationResult <IEnumerable <T> > or)
 {
     try
     {
         var items = repository.GetAllItems();
         or.SetData(items);
         return(true);
     }
     catch (Exception e)
     {
         or.AddMessage(_localizedMessagesService.GetErrorMessage(ErrorMessageKeys.RepositoryError));
         return(false);
     }
 }
コード例 #4
0
        public bool GetItem <T>(int id, ICrudRepository <T> repository, GenericOperationResult <T> or) where T : class, new()
        {
            if (id == 0)
            {
                or.AddMessage(_localizedMessagesService.GetErrorMessage(ErrorMessageKeys.InvalidId));
                return(false);
            }

            try
            {
                var item = repository.GetItem(id);
                or.SetData(item);
                return(true);
            }
            catch (Exception e)
            {
                or.AddMessage(_localizedMessagesService.GetErrorMessage(ErrorMessageKeys.RepositoryError));
                return(false);
            }
        }