예제 #1
0
        public PaginaDeResultado <EstudanteViewModel> GetAll(int paginaNumero, int paginaTamanho)
        {
            var model = new EstudanteViewModel();

            try
            {
                int ExcludeRecords = (paginaTamanho * paginaNumero) - paginaNumero;
                List <EstudanteViewModel> detalheList = new List <EstudanteViewModel>();
                var modelList  = _unitOfWork.GenericRepository <Estudante>().GetAll().Skip(ExcludeRecords).Take(paginaTamanho).ToList();
                var contaTotal = _unitOfWork.GenericRepository <Estudante>().GetAll().ToList();

                detalheList = GroupListInfo(modelList);
                if (detalheList != null)
                {
                    model.EstudanteList = detalheList;
                    model.ContaTotal    = contaTotal.Count();
                }
            }
            catch (Exception ex)
            {
                _ILogger.LogError(ex.Message);
            }

            var resultado = new PaginaDeResultado <EstudanteViewModel>
            {
                Data          = model.EstudanteList,
                TotalItems    = model.ContaTotal,
                PaginaNumero  = paginaNumero,
                PaginaTamanho = paginaTamanho,
            };

            return(resultado);
        }
        public async Task <IActionResult> Create(EstudanteViewModel usuarioViewModel)
        {
            if (ModelState.IsValid)
            {
                await _estudanteService.AddAsync(usuarioViewModel);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(_estudanteService));
        }
예제 #3
0
 public async Task <EstudanteViewModel> AddAsync(EstudanteViewModel vm)
 {
     try
     {
         Estudante objeto = vm.ConvertEstudanteViewModel(vm);
         await _unitOfWork.GenericRepository <Estudante>().AddAsync(objeto);
     }
     catch (Exception ex)
     {
         return(null);
     }
     return(vm);
 }
        public IActionResult Perfil([FromForm] EstudanteViewModel estudanteViewModel)
        {
            if (estudanteViewModel.ImagemArquivo != null)
            {
                estudanteViewModel.ImagemNomeArquivo = SaveEstudanteArquivo(estudanteViewModel.ImagemArquivo);
            }

            if (estudanteViewModel.CVArquivo != null)
            {
                estudanteViewModel.CVNomeArquivo = SaveEstudanteArquivo(estudanteViewModel.CVArquivo);
            }

            _estudanteService.UpdateAsync(estudanteViewModel);
            return(RedirectToAction("Perfil"));
        }
예제 #5
0
        public async Task <EstudanteViewModel> UpdateAsync(EstudanteViewModel vm)
        {
            try
            {
                Estudante objeto = _unitOfWork.GenericRepository <Estudante>().GetByID(vm.Id);
                objeto.Nome              = vm.Nome;
                objeto.UsuarioNome       = vm.UsuarioNome;
                objeto.ImagemNomeArquivo = vm.ImagemNomeArquivo != null ?
                                           vm.ImagemNomeArquivo : objeto.ImagemNomeArquivo;
                objeto.CVNomeArquivo = vm.CVNomeArquivo != null ?
                                       vm.CVNomeArquivo : objeto.CVNomeArquivo;
                objeto.Contato = vm.Contato;
                await _unitOfWork.GenericRepository <Estudante>().UpdateAsync(objeto);

                _unitOfWork.Save();
            }
            catch (Exception)
            {
                throw;
            }
            return(vm);
        }