public ActionResult AdicionaEmprestimo(emprestimo_jogo Emprestimo) { try { Emprestimo.data = DateTime.Now; Emprestimo.status = "e"; contexto.emprestimo_jogo.Add(Emprestimo); contexto.SaveChanges(); TempData["sucess"] = "Emprestimo salvo com sucesso"; } catch (Exception e) { TempData["error"] = "Erro ao salvar o Emprestimo"; } return(RedirectToAction("ListaEmprestimos")); }
public ActionResult EditaEmprestimo(emprestimo_jogo Emprestimo) { try { Emprestimo.status = "e"; contexto.Entry(Emprestimo).State = System.Data.Entity.EntityState.Modified; contexto.SaveChanges(); TempData["sucess"] = "Emprestimo atualizado com sucesso"; } catch (Exception e) { TempData["error"] = "Erro ao atualizar o cadastro do Emprestimo!"; } return(RedirectToAction("ListaEmprestimos")); }
public ActionResult EditaEmprestimo(int id) { try { emprestimo_jogo Emprestimo = (from c in contexto.emprestimo_jogo where c.id == id select c).SingleOrDefault(); ViewData["idAmigo"] = new SelectList((from c in contexto.Amigo where c.ativo == true orderby c.nome select c).ToList(), "id", "nome", Emprestimo.idAmigo); var emprestados = (from c in contexto.emprestimo_jogo where c.status == "e" && c.idJogo != Emprestimo.idJogo select c.Jogo).ToList(); var jogos = (from c in contexto.Jogo where c.ativo == true orderby c.titulo select c).ToList(); var jogosDisponiveis = jogos.Except(emprestados).ToList(); ViewData["idJogo"] = new SelectList(jogosDisponiveis, "id", "titulo", Emprestimo.idJogo); return(View(Emprestimo)); } catch (Exception e) { return(RedirectToAction("ListaEmprestimos")); } }
public ActionResult AdicionaEmprestimo() { try { ViewData["idAmigo"] = new SelectList((from c in contexto.Amigo where c.ativo == true orderby c.nome select c).ToList(), "id", "nome"); var emprestados = (from c in contexto.emprestimo_jogo where c.status == "e" select c.Jogo).ToList(); var jogos = (from c in contexto.Jogo where c.ativo == true orderby c.titulo select c).ToList(); var jogosDisponiveis = jogos.Except(emprestados).ToList(); ViewData["idJogo"] = new SelectList(jogosDisponiveis, "id", "titulo"); emprestimo_jogo Emprestimo = new emprestimo_jogo(); return(View(Emprestimo)); } catch (Exception e) { return(RedirectToAction("ListaEmprestimos")); } }