public IHttpActionResult DeleteBlackItem(int id_user, string product) { Product p = db.Products.SingleOrDefault(x => x.Name_Product == product); if (p == null) { p = new Product(); p.Name_Product = product; p.Visible = true; db.Products.Add(p); db.SaveChanges(); Black_Item bi = new Black_Item(); bi.Id_Product = p.Id_Product; bi.Id_User = id_user; db.Black_Items.Add(bi); db.SaveChanges(); } else { Black_Item bi = new Black_Item(); bi.Id_Product = p.Id_Product; bi.Id_User = id_user; db.Black_Items.Add(bi); db.SaveChanges(); } return(Ok("Added")); }
public IHttpActionResult DeleteBlackItem(int id_user, int id_product) { Black_Item bi = db.Black_Items.SingleOrDefault(x => x.Id_User == id_user && x.Id_Product == id_product); db.Black_Items.Remove(bi); db.SaveChanges(); return(Ok("Removed")); }