protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["id"] == null) { Response.Redirect("ConsultarAcervo.aspx"); } LivroDAO livroDAO = new LivroDAO(); String idLivro = Request.QueryString.Get("id").ToString(); Livro livro = livroDAO.getById(Convert.ToInt32(idLivro)); HttpContext.Current.Items.Add("Livro", livro); CategoriaLivroDAO categoriaDAO = new CategoriaLivroDAO(); HttpContext.Current.Items.Add("categorias", categoriaDAO.Listar()); CarrinhoDAO carrinhoDAO = new CarrinhoDAO(); Livraria.Model.Carrinho carrinho = carrinhoDAO.getCarrinhoById(Convert.ToInt32(Request.Cookies["idCarrinho"].Value.ToString())); bool temLivro = false; foreach (Livro l in carrinho.Livros) { if (l.Id == livro.Id) { temLivro = true; break; } } HttpContext.Current.Items.Add("temLivro", temLivro); }
protected void Page_Load(object sender, EventArgs e) { // listagem de categorias CategoriaLivroDAO categoriaDAO = new CategoriaLivroDAO(); HttpContext.Current.Items.Add("categorias", categoriaDAO.Listar()); // verificando a existência de carrinho carrinhoDAO = new CarrinhoDAO(); HttpCookie idCarrinhoCookie = Request.Cookies["idCarrinho"]; if (idCarrinhoCookie == null) { idCarrinhoCookie = new HttpCookie("idCarrinho", carrinhoDAO.addCarrinho().ToString()); Response.Cookies.Add(idCarrinhoCookie); } Livraria.Model.Carrinho carrinho = carrinhoDAO.getCarrinhoById(Convert.ToInt32(idCarrinhoCookie.Value.ToString())); // pediu para adicionar um novo livro ao carrinho? livroDAO = new LivroDAO(); string idAddLivro = Request.QueryString.Get("add"); if (idAddLivro != null) { carrinhoDAO.addLivro(carrinho, livroDAO.getById(Convert.ToInt32(idAddLivro))); carrinho = carrinhoDAO.getCarrinhoById(Convert.ToInt32(idCarrinhoCookie.Value.ToString())); HttpContext.Current.Items.Add("Carrinho", carrinho); Response.Redirect("Carrinho.aspx"); } HttpContext.Current.Items.Add("Carrinho", carrinho); }
private void OnCarrinhoRemoved(Carrinho carrinhoRem) { CarrinhoLivro cl = CarrinhoLivros.SingleOrDefault(cl2 => cl2.Livro == this && cl2.Carrinho == carrinhoRem); if (cl != null) { cl.Remove(); // method Remove() defined below } }
private void onCarrinhoAdicionado(Carrinho carrinhoAdded) { CarrinhoLivro cl = new CarrinhoLivro() { Carrinho = carrinhoAdded, Livro = this }; }