Exemplo n.º 1
0
        public ActionResult Create()
        {
            ProdutoCategoriaService Categorias = new ProdutoCategoriaService();

            ViewBag.CategoriaId = new SelectList(Categorias.GetAll(), "CategoriaId", "Nome");
            return(View());
        }
        public static MvcHtmlString SelectProdutoCategoria(this HtmlHelper html, int idProdutoCategoria = 0)
        {
            var cargos = new ProdutoCategoriaService().Listar()
                         .Where(x => x.Ativo == true)
                         .OrderBy(x => x.Descricao)
                         .ToList();

            TagBuilder tag = new TagBuilder("select");

            tag.MergeAttribute("id", "ProdutoCategoriaId");
            tag.MergeAttribute("name", "ProdutoCategoriaId");
            tag.MergeAttribute("class", "form-control");

            foreach (var item in cargos)
            {
                TagBuilder itemTag = new TagBuilder("option");
                itemTag.MergeAttribute("value", item.ProdutoCategoriaId.ToString());
                if (item.ProdutoCategoriaId == idProdutoCategoria)
                {
                    itemTag.MergeAttribute("selected", "selected");
                }
                itemTag.SetInnerText(item.Descricao);
                tag.InnerHtml += itemTag.ToString();
            }

            return(new MvcHtmlString(tag.ToString()));
        }
Exemplo n.º 3
0
        public ActionResult Edit(int?id)
        {
            ProdutoSubcategoria          Subcategoria   = Service.GetById(id.GetValueOrDefault());
            ProdutoSubcategoriaViewModel SubcategoriaVM = Mapper.Map <ProdutoSubcategoria, ProdutoSubcategoriaViewModel>(Subcategoria);

            ProdutoCategoriaService Categorias = new ProdutoCategoriaService();

            ViewBag.CategoriaId = new SelectList(Categorias.GetAll(), "CategoriaId", "Nome");

            return(View(SubcategoriaVM));
        }
Exemplo n.º 4
0
        public ActionResult Create([Bind(Include = "SubcategoriaId,Nome,CategoriaId")] ProdutoSubcategoriaViewModel produtoSubcategoriaViewModel)
        {
            if (ModelState.IsValid)
            {
                ProdutoSubcategoria Subcategoria = Mapper.Map <ProdutoSubcategoriaViewModel, ProdutoSubcategoria>(produtoSubcategoriaViewModel);
                Service.Insert(Subcategoria);
                return(RedirectToAction("Index"));
            }

            ProdutoCategoriaService Categorias = new ProdutoCategoriaService();

            ViewBag.CategoriaId = new SelectList(Categorias.GetAll(), "CategoriaId", "Nome");
            return(View(produtoSubcategoriaViewModel));
        }
Exemplo n.º 5
0
 public CategoriasController()
 {
     AutoMapperHelper.InitializeMapper();
     CategoriaService = new ProdutoCategoriaService();
 }
Exemplo n.º 6
0
        public SelectList SelectCategorias()
        {
            ProdutoCategoriaService Categorias = new ProdutoCategoriaService();

            return(new SelectList(Categorias.GetAll(), "CategoriaId", "Nome"));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Returns a view to edit a product
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Editar(int id)
        {
            //Retorna o produto
            var produto = new ProdutoService().GetById(id);

            //Instância das Controllers
            var marcaController = new MarcaController();
            var linhaController = new LinhaController();
            var tipoPeleController = new TipoPeleController();

            //Instância das Services
            var categoriaService = new CategoriaService();
            var aplicacaoService = new AplicacaoService();
            var idiomaService = new IdiomaService();
            var produtoCategoriaService = new ProdutoCategoriaService();
            var produtoAplicacaoService = new ProdutoAplicacaoService();
            var produtoTipoService = new ProdutoTipoProdutoService();
            var tipoService = new TipoProdutoService();

            //GetAll
            var getAllAplicacoes = aplicacaoService.GetAll();
            var getAllCategorias = categoriaService.GetCategoriesAddMasterCateg();
            var getAllIdiomas = idiomaService.GetAll();
            var getAllTipos = tipoService.GetAll();

            //GetByProductId
            var getAllProdutoCategorias = produtoCategoriaService.GetRecords(x => x.IdProduto == produto.IdProduto);
            var getAllProdutoAplicacoes = produtoAplicacaoService.GetRecords(x => x.IdProduto == produto.IdProduto);
            var getAllProdutoTipos = produtoTipoService.GetRecords(x => x.IdProduto == produto.IdProduto);
            
            //Adicionando SelectListItens na ViewBag
            ViewBag.Marks = marcaController.GetMarkSelectListItem(new MarcaService().GetAll(), null);
            ViewBag.Lines = linhaController.GetLineSelectListItem(new LinhaService().GetAll(), null);
            ViewBag.Skins = tipoPeleController.GetSkinTypeSelectListItem(new TipoPeleService().GetAll(), null);
            ViewBag.Categories = GetProdCategoryListItem(getAllCategorias, null);
            ViewBag.Applications = GetProdAppListItem(getAllAplicacoes, produto.IdProduto);
            ViewBag.Types = GetProdTypesListItem(getAllTipos, null);
            ViewBag.Idiomas = getAllIdiomas;

            //Adicionando valores selecionados na ViewBag
            ViewBag.selApplications = CreateApplicationsSelectedList(getAllAplicacoes,
                                                                     getAllProdutoAplicacoes);

            ViewBag.selCategories = CreateCategoriesSelectedList(getAllCategorias,
                                                                 getAllProdutoCategorias);

            ViewBag.selTypes = CreateTypesSelectedList(getAllTipos,
                                                     getAllProdutoTipos);

            return View(produto);
        }