Ejemplo n.º 1
0
        public ActionResult DeleteSelected(string[] ids)
        {
            int[] id = null;
            if (ids != null)
            {
                id = new int[ids.Length];
                int j = 0;
                foreach (string i in ids)
                {
                    int.TryParse(i, out id[j++]);
                }
            }

            if (id != null && id.Length > 0)
            {
                List <tbl_Product> allSelected = new List <tbl_Product>();
                using (CSharpAssignment2Entities db = new CSharpAssignment2Entities())
                {
                    allSelected = db.tbl_Product.Where(a => id.Contains(a.id)).ToList();
                    try
                    {
                        foreach (var i in allSelected)
                        {
                            db.tbl_Product.Remove(i);
                            db.SaveChanges();
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex, "Error occured in Product controller Delete Product POST Action");
                    }
                }
            }
            return(RedirectToAction("ProductList"));
        }