コード例 #1
0
        public ActionResult Delete(int?id)
        {
            try
            {
                if (id == null)
                {
                    TempData["Message"] = "Debe ingresar un ID valido de producto para eliminar";

                    return(RedirectToAction("Index"));
                }

                Product product = ctx.Products.Find(id);

                if (!RepositoryProduct.DeleteProduct(ctx, product))
                {
                    TempData["Message"] = "No puede eliminar un producto que ya fue pedido";

                    return(RedirectToAction("Index"));
                }

                TempData["Message"] = "Eliminacion correcta";

                return(RedirectToAction("Index"));
            }

            catch (Exception e)
            {
                TempData["Message"] = "Problema al cambiar estado -> " + e.Message;

                return(RedirectToAction("Index"));
            }
        }
コード例 #2
0
        public async Task <string> DeleteProduct(int sku)
        {
            var producExisting = await GetProduct(sku);

            if (producExisting == null)
            {
                return("Não existe produto com o sku informado!");
            }

            return(await _repositoryProduct.DeleteProduct(sku));
        }
コード例 #3
0
        protected void deleteproduct_Click(object sender, EventArgs e)
        {
            Int32 deletebyID = 0;

            Int32.TryParse(id.Text.ToString(), out deletebyID);
            bool cek = RepositoryProduct.CekID(deletebyID);

            if (cek)
            {
                RepositoryProduct.DeleteProduct(deletebyID);
                Response.Write("<script>alert('Delete product successfully.')</script>");
                refresh();
            }
            else
            {
                Response.Write("<script>alert('ID does not exists.')</script>");
            }
        }