public EmprestimoViewModel GetEmprestimoById(int id) { try { db.ClearParameters(); db.AddParameters("@Id", id); String cmd = @"SELECT * FROM dbo.Emprestimo WITH (NOLOCK) WHERE ID_Emprestimo = @Id"; DataTable dt = db.ExecuteR(System.Data.CommandType.Text, cmd); EmprestimoViewModel emp = null; DateTime? DH_NULL = new Nullable <DateTime>(); foreach (DataRow dr in dt.Rows) { EmprestimoViewModel _emp = new EmprestimoViewModel(); _emp.ID_Emprestimo = Convert.ToInt32(dr["ID_Emprestimo"]); _emp.ID_Jogo = Convert.ToInt32(dr["ID_Jogo"]); _emp.ID_Amigo = Convert.ToInt32(dr["ID_Amigo"]); _emp.DH_Devolucao = Equals(dr["DH_Devolucao"]) ? Convert.ToDateTime(dr["DH_Devolucao"]) : DH_NULL; _emp.DH_Emprestimo = Convert.ToDateTime(dr["DH_Emprestimo"]); emp = _emp; } return(emp); } catch (Exception e) { throw new Exception(e.Message); } }
public JsonResult Salvar(EmprestimoViewModel model) { model.Emprestimo.Data = DateTime.Now; var retorno = new BusinessPessoaJogo().Salvar(model.Emprestimo); return(Json(retorno, JsonRequestBehavior.AllowGet)); }
public HttpResponseMessage ManterEmprestimo(EmprestimoViewModel model) { try { if (model != null) { var emprestimo = Mapper.Map <EmprestimoViewModel, Emprestimo>(model); emprestimo.JogoId = model.JogoId; emprestimo.AmigoId = model.AmigoId; emprestimo.Observacao = model.Observacao; if (emprestimo.EmprestimoId > 0) { var emp = _emprestimoService.RecuperarPorId(emprestimo.EmprestimoId); emp.Observacao = model.Observacao; _emprestimoService.Atualizar(emp); } else { AdicionarNovoEmprestimo(emprestimo); } AtualizarSituacaoEmprestimoJogo(emprestimo.JogoId, true); } HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK); return(response); } catch (Exception ex) { HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message); return(response); } }
private async Task <EmprestimoFormViewModel> GetForm(EmprestimoViewModel emprestimoViewModel) { var form = EmprestimoFormViewModel.Clone(emprestimoViewModel); form.AddAmigos(await _amigoService.GetAll()); form.AddGames(await _gameService.GetGamesDisponiveis()); if (form.GameId > 0) { form.AddGame(new GameViewModel() { Id = form.GameId, Nome = form.AmigoNome }); } if (form.AmigoId > 0) { form.AddAmigo(new AmigoViewModel() { Id = form.GameId, Nome = form.AmigoNome }); } return(form); }
public EmprestimoViewModel Atualizar(EmprestimoViewModel obj) { var mappedModel = Mapper.Map <EmprestimoViewModel, Emprestimo>(obj); var updateModel = _service.Atualizar(mappedModel); return(Mapper.Map <Emprestimo, EmprestimoViewModel>(updateModel)); }
public EmprestimoViewModel Adicionar(EmprestimoViewModel obj) { var mappedModel = Mapper.Map <EmprestimoViewModel, Emprestimo>(obj); var addedModel = _service.Adicionar(mappedModel); return(Mapper.Map <Emprestimo, EmprestimoViewModel>(addedModel)); }
public ActionResult Edit(EmprestimoViewModel emp) { if (ModelState.IsValid) { rEmp.UpdateEmprestimo(emp); return(RedirectToAction("Index")); } return(View(emp)); }
public ActionResult Index() { var model = new EmprestimoViewModel(); model.Jogos = PopularComboJogos(model); model.Amigos = PopularComboAmigos(model); return(View(model)); }
// GET: Emprestimos/Edit/5 public ActionResult Edit(int id) { EmprestimoViewModel emprestimoViewModel = Mapper.Map <Emprestimo, EmprestimoViewModel>(_wcfServiceClient.GetEmprestimoById(id)); emprestimoViewModel.Clientes = GetClientesDropDownList(); emprestimoViewModel.Materiais = GetMateraisDropDownList(); return(View(emprestimoViewModel)); }
private bool DataDevolucaoValidas(EmprestimoViewModel emprestimoVm) { if (emprestimoVm.DataDevolucao.HasValue && emprestimoVm.DataDevolucao < emprestimoVm.DataEmprestimo) { ModelState.AddModelError("", "Data de devolução não pode ser menor que a data de empréstimo."); return(false); } return(true); }
private EmprestimoViewModel GetEmprestimoViewModelAdicao() { List <Livros> livros = this._dataService.GetLivros(); List <Usuarios> usuarios = this._dataService.GetUsuarios(); EmprestimoViewModel viewModel = new EmprestimoViewModel(livros, usuarios); return(viewModel); }
public ActionResult CreateStep1(int id) { var emprestimoViewModel = new EmprestimoViewModel(); emprestimoViewModel.ExemplarLivroId = id; MapearUmExemplar(emprestimoViewModel); return(View(emprestimoViewModel)); }
public IActionResult EmprestarLivro(Guid livroId) { var emprestimoViewModel = new EmprestimoViewModel() { Livro = _repositorioLivro.BuscarPorId(livroId), Clientes = _repositorioCliente.BuscarTodos() }; return(View(emprestimoViewModel)); }
private void MapearUmExemplar(EmprestimoViewModel emprestimoViewModel) { emprestimoViewModel.ExemplarLivro = Mapper.Map <ExemplarLivro, ExemplarLivroViewModel>(_exemplarLivroAppServico.ObterPorId(emprestimoViewModel.ExemplarLivroId)); emprestimoViewModel.ExemplarLivro.Livro = Mapper.Map <Livro, LivroViewModel>(_livroAppServico.ObterPorId(emprestimoViewModel.ExemplarLivro.LivroId)); emprestimoViewModel.ExemplarLivro.Livro.Autor = Mapper.Map <Autor, AutorViewModel>(_autorAppServico.ObterPorId(emprestimoViewModel.ExemplarLivro.Livro.AutorId)); emprestimoViewModel.ExemplarLivro.Livro.Assunto = Mapper.Map <Assunto, AssuntoViewModel>(_assuntoAppServico.ObterPorId(emprestimoViewModel.ExemplarLivro.Livro.AssuntoId)); emprestimoViewModel.ExemplarLivro.Livro.Editora = Mapper.Map <Editora, EditoraViewModel>(_editoraAppServico.ObterPorId(emprestimoViewModel.ExemplarLivro.Livro.EditoraId)); emprestimoViewModel.ExemplarLivro.Livro.Classificacao = Mapper.Map <Classificacao, ClassificacaoViewModel>(_classificacaoAppServico.ObterPorId(emprestimoViewModel.ExemplarLivro.Livro.ClassificacaoId)); emprestimoViewModel.ExemplarLivro.Livro.Localizacao = Mapper.Map <Localizacao, LocalizacaoViewModel>(_localizacaoAppServico.ObterPorId(emprestimoViewModel.ExemplarLivro.Livro.LocalizacaoId)); }
// GET: Emprestimos/Create public ActionResult Create() { EmprestimoViewModel emprestimoViewModel = new EmprestimoViewModel { Clientes = GetClientesDropDownList(), Materiais = GetMateraisDropDownList() }; return(View(emprestimoViewModel)); }
public async Task <IActionResult> ConfirmarEmprestimo([FromBody] EmprestimoViewModel emprestimoViewModel) { var emprestimo = await _emprestimoServico.ConfirmaEmprestimo(emprestimoViewModel); if (_emprestimoServico.Sucesso()) { return(Ok(emprestimo)); } return(BadRequest(_emprestimoServico.Erros)); }
public async Task <IActionResult> RealizaDevolucao([FromBody] EmprestimoViewModel emprestimoViewModel) { var emprestimo = await _emprestimoServico.RealizaDevolucao(emprestimoViewModel); if (_emprestimoServico.Sucesso()) { return(Ok(emprestimo)); } return(BadRequest(_emprestimoServico.Erros)); }
protected override void OnAppearing() { base.OnAppearing(); if (!dadosCarregados) { viewModel = new EmprestimoViewModel(App.ParticipanteId.GetValueOrDefault()); this.BindingContext = viewModel; dadosCarregados = true; } }
public IActionResult EmprestarLivro(EmprestimoViewModel emprestimoViewModel) { var livro = _repositorioLivro.BuscarPorId(emprestimoViewModel.Livro.LivroId); var cliente = _repositorioCliente.BuscarPorId(emprestimoViewModel.Livro.ClienteId); livro.Cliente = cliente; _repositorioLivro.Atualizar(livro); return(RedirectToAction("Listar")); }
public ActionResult Cadastrar(EmprestimoViewModel emprestimo) { Emprestimo e = new Emprestimo(); e.DtDevolucao = emprestimo.DtDevolucao; e.DtEmprestimo = emprestimo.DtEmprestimo; e.LivroId = emprestimo.LivroId; e.PessoaId = emprestimo.PessoaId; _emprestimoService.Inserir(e); return(RedirectToAction("Cadastrar")); }
public async Task <IActionResult> Post([FromBody] EmprestimoViewModel viewModel) { var emprestimoGerenciamento = _provider.GetRequiredService <EmprestimoGerenciamento>(); if (!await emprestimoGerenciamento.Insert(viewModel.MapTo(new Emprestimo()))) { return(new EmprestimoErrorJson(emprestimoGerenciamento)); } return(Created()); }
public async Task <EmprestimoViewModel> Edit(EmprestimoViewModel model) { var url = API.Emprestimo.PutEmprestimo(_enderecoRemoto); var authorizationToken = await GetUserTokenAsync(); var response = await _apiClient.PutAsync(url, model, authorizationToken); response.EnsureSuccessStatusCode(); return(model); }
// GET: Emprestimos/Details/5 public ActionResult Details(int id) { EmprestimoViewModel emprestimoViewModel = Mapper.Map <Emprestimo, EmprestimoViewModel>(_wcfServiceClient.GetEmprestimoById(id)); emprestimoViewModel.ClienteNome = _wcfServiceClient.GetClienteById(emprestimoViewModel.ClienteId).Nome; emprestimoViewModel.MaterialDescricao = _wcfServiceClient.GetMaterialById(emprestimoViewModel.MaterialId).Descricao; emprestimoViewModel.DataDevolucaoDescricao = emprestimoViewModel.DataDevolucao != DateTime.MinValue ? emprestimoViewModel.DataDevolucao.ToString("dd/MM/yyyy") : "-"; emprestimoViewModel.DataDevolverDescricao = emprestimoViewModel.DataDevolver.ToString("dd/MM/yyyy"); emprestimoViewModel.DevolvidoDescricao = emprestimoViewModel.Devolvido ? "Sim" : "Não"; return(View(emprestimoViewModel)); }
public async Task <IActionResult> Create(EmprestimoViewModel emprestimoViewModel) { emprestimoViewModel = await PopularJogos(emprestimoViewModel); if (!ModelState.IsValid) { return(CustomResponse(ModelState)); } await _emprestimoService.Adicionar(_mapper.Map <Emprestimo>(emprestimoViewModel)); return(RedirectToAction("Index")); }
public ActionResult Visualizar(int codigo) { EmprestimoViewModel modelVM = new EmprestimoViewModel(); var model = _emprestimoService.RecuperarPorId(codigo); if (model != null) { modelVM = Mapper.Map <Emprestimo, EmprestimoViewModel>(model); } return(View(modelVM)); }
public async Task <IActionResult> Save(EmprestimoViewModel vm) { try { var result = await _controleService.Lend(vm); return(Ok(result)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public IActionResult Cadastro(int id) { if (id > 0) { var emprestimo = this._dataService.GetEmprestimo(id); EmprestimoViewModel viewModel = GetEmprestimoViewModelEdicao(emprestimo); return(View(viewModel)); } else { EmprestimoViewModel viewModel = GetEmprestimoViewModelAdicao(); return(View(viewModel)); } }
// GET: Emprestimo/Edit/5 public ActionResult Edit(int id) { var repositoryEmprestimos = new EmprestimoRepository(); var emprestimo = repositoryEmprestimos.GetEmprestimoById(id); EmprestimoViewModel emprestimoVM = new EmprestimoViewModel(); emprestimoVM.id = emprestimo.id; emprestimoVM.dataEmprestimo = emprestimo.dataEmprestimo; emprestimoVM.dataDevolucao = emprestimo.dataDevolucao; emprestimoVM.idLivro = emprestimo.idLivro; return(View(emprestimoVM)); }
public Task <ControleViewModel> Lend(EmprestimoViewModel vm) { var controle = new Controle { Chave = _context.Chaves.Find(vm.ChaveID), FuncionarioRetirada = _context.Funcionarios.Find(vm.FuncionarioID), Retirada = vm.Data, UsuarioRetirada = CurrentUser }; _context.Controles.Add(controle); _context.SaveChanges(); return(Task.FromResult(_mapper.Map <ControleViewModel>(controle))); }
// GET: Emprestimos/Create public ActionResult Create(int id) { var repository = new LivroRepository(); var emprestimo = repository.DetailLivro(id); var emprestimoViewModel = new EmprestimoViewModel { LivroId = emprestimo.Id, Titulo = emprestimo.Titulo, DataEmprestimo = DateTime.Today, DataDevolucao = DateTime.Today.AddDays(10) }; return(View(emprestimoViewModel)); }