Пример #1
0
        public async Task <IActionResult> Index()
        {
            IList <ExamViewModel> exams = new List <ExamViewModel>();

            if (User.Role() == "Administrator")
            {
                exams = _repos.Exams
                        .ListWith("Unit")
                        .Select(TransformFuncs.ToViewModel())
                        .ToList();

                return(Ok(exams));
            }

            AppUser user = await _usermanager.GetUserAsync(User);

            if (User.Role() == "Lecturer")
            {
                exams = _dataManager.MyExams <Lecturer>(user.AccountId);
            }
            else if (User.Role() == "Student")
            {
                exams = _dataManager.MyExams <Student>(user.AccountId);
            }

            return(Ok(exams));
        }
Пример #2
0
 /// <summary>
 /// Mapeia o objeto de origem e assume que  o de destino será igual
 /// </summary>
 /// <param name="sourceField">Nome do campo mapeado</param>
 /// <param name="destinationField">Nome do campo de destino para o mapeamento</param>
 /// <returns></returns>
 public Transform Map(string sourceField, string destinationField)
 {
     TransformMap[sourceField] = destinationField;
     if (TransformFuncs.ContainsKey(sourceField))
     {
         TransformFuncs.Remove(sourceField);
     }
     return(this);
 }
Пример #3
0
 /// <summary>
 /// Remove o mapeamento existente entre origem e destino
 /// </summary>
 /// <param name="sourceField"></param>
 /// <returns></returns>
 public Transform Unmap(string sourceField)
 {
     if (TransformMap.ContainsKey(sourceField))
     {
         TransformMap.Remove(sourceField);
     }
     if (TransformFuncs.ContainsKey(sourceField))
     {
         TransformFuncs.Remove(sourceField);
     }
     return(this);
 }
Пример #4
0
        public IActionResult GetByUnit(int id)
        {
            IList <ExamViewModel> exams = new List <ExamViewModel>();

            exams = _repos.Units.GetWith(id, "Exams", "Exams.Unit")
                    ?.Exams
                    .Select(TransformFuncs.ToViewModel())
                    .TakeWhile(x => x != null)
                    .ToList();

            return(Ok(exams));
        }
Пример #5
0
        /// <summary>
        /// Executa o processo de transformação do objeto e retorna o resultado transformado
        /// </summary>
        /// <returns></returns>
        public Transform Execute()
        {
            if (TransformMap.Count == 0)
            {
                throw new InvalidOperationException("No mappings defined.");
            }

            if (this.Start != null)
            {
                this.Start(this);
            }

            try
            {
                Source.InTransformContext(this, () =>
                {
                    _dest.InTransformContext(this, () =>
                    {
                        foreach (var inputRow in Source.Rows)
                        {
                            RowValidation rowValidation = new RowValidation();
                            DoRowValidation(inputRow, rowValidation);
                            if (rowValidation.HasErrors)
                            {
                                if (this.RowInvalid != null)
                                {
                                    this.RowInvalid(inputRow, rowValidation);
                                }
                            }
                            else
                            {
                                RowOperation rowOp = this.GetRowOperation(inputRow);
                                if (rowOp != RowOperation.Ignore)
                                {
                                    DictionaryRow transformedRow = new DictionaryRow();
                                    foreach (var mapping in TransformMap)
                                    {
                                        object rowValue = inputRow[mapping.Key];
                                        Func <object, object> transformFunc;
                                        if (TransformFuncs.TryGetValue(mapping.Key, out transformFunc))
                                        {
                                            rowValue = transformFunc(rowValue);
                                        }
                                        transformedRow[mapping.Value] = rowValue;
                                    }

                                    ProcessTransformedRow(rowOp, transformedRow);
                                }
                            }
                        }
                    });
                });
            }
            catch (Exception exTransform)
            {
                if (this.Error != null)
                {
                    this.Error(this, exTransform);
                }
                else
                {
                    throw exTransform;
                }
            }

            if (this.Complete != null)
            {
                this.Complete(this);
            }

            return(this);
        }