public void Delete(Guid id) { XbooxLibraryDBContext context = new XbooxLibraryDBContext(); GeneralRepository <Product> repository = new GeneralRepository <Product>(context); GeneralRepository <ProductImgs> Imgrepository = new GeneralRepository <ProductImgs>(context); GeneralRepository <ProductTags> Ptrepository = new GeneralRepository <ProductTags>(context); var deleteProduct = repository.GetFirst(x => x.ProductId == id); var deleteImg = Imgrepository.GetAll().Where(x => x.ProductId == id); var deleteTag = Ptrepository.GetAll().Where(x => x.ProductId == id); if (deleteImg != null) { foreach (var i in deleteImg) { Imgrepository.Delete(i); } } if (deleteTag != null) { foreach (var i in deleteTag) { Ptrepository.Delete(i); } } //刪除product 刪除 tag repository.Delete(deleteProduct); context.SaveChanges(); }
public OperationResult DeleteConfirmed(Guid id) { var result = new OperationResult(); try { XbooxLibraryDBContext context = new XbooxLibraryDBContext(); GeneralRepository <Coupons> couRepo = new GeneralRepository <Coupons>(context); Coupons coupons = context.Coupons.Find(id); context.Coupons.Remove(coupons); context.SaveChanges(); result.IsSuccessful = true; } catch (Exception ex) { result.IsSuccessful = false; result.exception = ex; } return(result); }
public void SaveContext() { context.SaveChanges(); }