示例#1
0
        /* Pasamos una vista para que sea más fácil de editar el JSON y luego
         * lo transformamos en un Products para se pueda actualizar */
        public IHttpActionResult PutProducts(/*int id, */ ProductsView productsView)
        {
            Products product = new Products
            {
                ProductID       = productsView.Id,
                ProductName     = productsView.Name,
                QuantityPerUnit = productsView.QuantityPerUnit,
                UnitPrice       = productsView.Price,
            };

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //if (id != product.ProductID) return BadRequest();

            try
            {
                productsLogic.Update(product);
                return(Ok());
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#2
0
        protected void btnEditar_Click(object sender, EventArgs e)
        {
            ProductsLogic productsLogic = new ProductsLogic();

            Products product = new Products
            {
                ProductID       = productID,
                ProductName     = this.txtNombre.Text,
                QuantityPerUnit = this.txtCantidad.Text,
                UnitPrice       = decimal.Parse(this.txtPrecio.Text)
            };

            productsLogic.Update(product);

            Response.Redirect("Default.aspx");
        }
示例#3
0
        public ActionResult InsertEdit(ProductsView productsView)
        {
            if (ModelState.IsValid)
            {
                if (productsView.Id <= 0)
                {
                    try
                    {
                        Products productEntity = new Products
                        {
                            ProductName     = productsView.Name,
                            QuantityPerUnit = productsView.QuantityPerUnit,
                            UnitPrice       = productsView.Price,
                        };

                        logic.Add(productEntity);

                        return(RedirectToAction("Index"));
                    }
                    catch (FormatException ex)
                    {
                        string error = $"Price error, non-numeric value was entered. Error: {ex.Message}";
                        TempData["MensajeError"] = error;

                        LogErrorsLogic logErrorsLogic = new LogErrorsLogic();
                        logErrorsLogic.LogError(error);

                        return(RedirectToAction("Index", "Error"));
                    }
                    catch (Exception ex)
                    {
                        LogErrorsLogic logErrorsLogic = new LogErrorsLogic();
                        logErrorsLogic.LogError(ex.Message);

                        TempData["MensajeError"] = "There was a problem trying to save the product. Please go back and try again";
                        return(RedirectToAction("Index", "Error"));
                    }
                }
                else
                {
                    try
                    {
                        Products productEntity = new Products
                        {
                            ProductID       = productsView.Id,
                            ProductName     = productsView.Name,
                            QuantityPerUnit = productsView.QuantityPerUnit,
                            UnitPrice       = productsView.Price,
                        };

                        logic.Update(productEntity);

                        return(RedirectToAction("Index"));
                    }
                    catch (Exception ex)
                    {
                        LogErrorsLogic logErrorsLogic = new LogErrorsLogic();
                        logErrorsLogic.LogError(ex.Message);

                        TempData["MensajeError"] = "There was a problem trying to save the product. Please go back and try again";
                        return(RedirectToAction("Index", "Error"));
                    }
                }
            }
            return(View());
        }