public static Result removerItem(Long produto) { Form<FormularioCompra> formulario = Form.form(FormularioCompra.class).bindFromRequest(); if (formulario.hasErrors()) { return badRequest(formularioCompra.render(formulario, new FormularioCompra())); } FormularioCompra item = formulario.get(); FormularioCompra dto = criarOuObterDTOCompraSessao(); dto.itens = removerItemDoDTO(produto, dto.itens); gravarDTOCompraSessao(dto); return ok(itens.render(dto.itens)); }
public static Result adicionarItem() { Form<FormularioCompra> formulario = Form.form(FormularioCompra.class).bindFromRequest(); if (formulario.hasErrors()) { return badRequest(formularioCompra.render(formulario, new FormularioCompra())); } FormularioCompra item = formulario.get(); FormularioCompra dto = criarOuObterDTOCompraSessao(); dto.cnpj = item.cnpj; if (item.produto != null) { dto.itens.add(item); gravarDTOCompraSessao(dto); } formulario = Form.form(FormularioCompra.class); return ok(itens.render(dto.itens)); }