コード例 #1
0
        public ActionResult Delete(int?id)
        {
            ProdutoSubcategoria          Subcategoria   = Service.GetById(id.GetValueOrDefault());
            ProdutoSubcategoriaViewModel SubcategoriaVM = Mapper.Map <ProdutoSubcategoria, ProdutoSubcategoriaViewModel>(Subcategoria);

            return(View(SubcategoriaVM));
        }
コード例 #2
0
        public ActionResult DeleteConfirmed(int?id)
        {
            ProdutoSubcategoria Subcategoria = Service.GetById(id.GetValueOrDefault());

            Service.Delete(Subcategoria);
            return(RedirectToAction("Index"));
        }
コード例 #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));
        }
コード例 #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));
        }
コード例 #5
0
        public async Task <IActionResult> PostProdutoSubcategoria([FromBody] ProdutoSubcategoria produtoSubcategoria)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (_context.ProdutoSubcategorias.Count(x => x.Nome == produtoSubcategoria.Nome && x.IdCategoria == produtoSubcategoria.IdCategoria) > 0)
            {
                return(BadRequest(new { message = "Já existe subcategoria com esse nome!" }));
            }

            _context.ProdutoSubcategorias.Add(produtoSubcategoria);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetProdutoSubcategoria", new { id = produtoSubcategoria.IdSubcategoria }, produtoSubcategoria));
        }
コード例 #6
0
        public async Task <IActionResult> PutProdutoSubcategoria([FromRoute] int id, [FromBody] ProdutoSubcategoria produtoSubcategoria)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != produtoSubcategoria.IdSubcategoria)
            {
                return(BadRequest());
            }

            if (_context.ProdutoSubcategorias.Count(x => x.Nome == produtoSubcategoria.Nome && x.IdCategoria == produtoSubcategoria.IdCategoria && x.IdSubcategoria != produtoSubcategoria.IdSubcategoria) > 0)
            {
                return(BadRequest(new { message = "Já existe subcategoria com esse nome!" }));
            }

            _context.Entry(produtoSubcategoria).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProdutoSubcategoriaExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }