예제 #1
0
        public ActionResult Create([Bind(Include = "prd_id,cat_id,prm_id,prd_nom,prd_img,prd_tal,prd_crt,prd_cnt,prd_prc,prd_dateOfCreated")] Producto producto)
        {
            HttpPostedFileBase fileBase = Request.Files[0];
            string             path     = SubirImagen(fileBase);

            if (path != "")
            {
                producto.prd_img = path;
            }
            else
            {
                producto.prd_img = "default";
            }

            if (ModelState.IsValid)
            {
                ProductoBLL.Create(producto);
                return(RedirectToAction("Index"));
            }
            //ViewBag.Menssage = file.FileName;
            ViewBag.cat_id = new SelectList(CategoriaBLL.List(), "cat_id", "cat_nom", producto.cat_id);
            ViewBag.prm_id = new SelectList(PromocionBLL.List(), "prm_id", "prm_nom", producto.prm_id);
            ViewBag.file   = fileBase;
            //producto.prd_img = SubirImagen(file);
            return(View(producto));
        }
        public ActionResult Create([Bind(Include = "idProducto,nombre,precio,comentario,estado")] Producto producto)
        {
            if (ModelState.IsValid)
            {
                ProductoBLL.Create(producto);
                return(RedirectToAction("Index"));
            }

            return(View(producto));
        }
 public IHttpActionResult Post(Producto producto)
 {
     try
     {
         ProductoBLL.Create(producto);
         return(Content(HttpStatusCode.Created, "Producto creado correctamente"));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
예제 #4
0
 public AgregarProductoResponse Agregar(AgregarProductoResponse dto)
 {
     try
     {
         var bc = new ProductoBLL();
         dto.Result = bc.Create(dto.Result);
         return(dto);
     }
     catch (Exception ex)
     {
         var httpError = new HttpResponseMessage()
         {
             StatusCode   = (HttpStatusCode)422, // UNPROCESSABLE ENTITY
             ReasonPhrase = ex.Message
         };
         dto.Message = ex.Message;
         throw new HttpResponseException(httpError);
     }
 }
        public IHttpActionResult Create(Producto producto)
        {
            HttpRequestMessage request = this.Request;

            if (!request.Content.IsMimeMultipartContent())
            {
                return(Content(HttpStatusCode.UnsupportedMediaType, "Error al crear Método Post debe ser MultipartContent"));
            }
            else
            {
                try
                {
                    var            httpRequest = HttpContext.Current.Request;
                    HttpPostedFile fileBase    = httpRequest.Files[0];
                    string         path        = SubirImagen(fileBase);
                    if (path != "")
                    {
                        try
                        {
                            producto.prd_img = path;
                            ProductoBLL.Create(producto);
                            return(Content(HttpStatusCode.Created, "Producto creado correctamente"));
                        }
                        catch (Exception ex)
                        {
                            return(BadRequest(ex.Message));
                        }
                    }
                    else
                    {
                        return(Content(HttpStatusCode.UnsupportedMediaType, "Error al obtener imagen"));
                    }
                }
                catch (Exception ex)
                {
                    return(Content(HttpStatusCode.InternalServerError, $"Internal server error: {ex}"));
                }
            }
        }
예제 #6
0
        public Producto Create(Producto Producto)
        {
            ProductoBLL ProductoBLL = new ProductoBLL();

            return(ProductoBLL.Create(Producto));
        }