Example #1
0
        public Response Crear(ProductoCategoriaRequest request)
        {
            ProductoCategoria categoria = this._unitOfWork.CategoriaRepository
                                          .FindBy(categoria => categoria.Nombre == request.NombreCategoria,
                                                  includeProperties: "SubCategorias").FirstOrDefault();

            if (categoria != null)
            {
                return(new Response
                {
                    Mensaje = "La categoria ya se encuentra registrada"
                });
            }

            categoria        = new ProductoCategoria();
            categoria.Nombre = request.NombreCategoria;

            this._unitOfWork.CategoriaRepository.Add(categoria);
            this._unitOfWork.Commit();


            return(new Response
            {
                Mensaje = $"Se ha registrado la categoria {categoria.Nombre} con éxito",
                Data = new ProductoCategoriaRequest().Map(categoria)
            });
        }
        public ActionResult <Response> PostCategoria(ProductoCategoriaRequest request)
        {
            Response response = new ProductoCategoriaCrearService(this._unitOfWork).Crear(request);

            return(Ok(response));
        }