public string Delete(int id) { var item = booksContext.Set <T>().FirstOrDefault(x => x.id == id); if (item == null) { return("not found"); } booksContext.Remove(item); return(item.id + " delete..."); }
public IActionResult Delete(int Id) { Category category = db.Categories.First(c => c.Id == Id); if (category != null) { db.Remove(category); db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Delete(int id) { var book = bookDB.Books.Find(id); if (book == null) { return(null); } bookDB.Remove(book); bookDB.SaveChanges(); return(RedirectToAction("Books")); }
public IActionResult Delete(int Id) { Book book = db.Books.First(b => b.Id == Id); string fullPath = $"{_hostingEnvironment.WebRootPath}{book.PhotoUrl}"; if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } if (book != null) { db.Remove(book); db.SaveChanges(); } return(RedirectToAction("Index")); }
public async Task <Result> Handle(DeleteBookRequest request, CancellationToken cancellationToken) { if (request.Id <= 0) { return(Result.Failure(ErrorCode.BadRequest)); } var book = await dbContext.Books.FirstOrDefaultAsync(b => b.Id == request.Id); if (book is null) { return(Result.Failure(ErrorCode.NotFound)); } dbContext.Remove(book); await dbContext.SaveChangesAsync(); return(Result.Success()); }
public async Task DeleteElem(Order elem) { _context.Remove(elem); await _context.SaveChangesAsync(); }
public void Delete(int id) { db.Remove(db.Books.Find(id)); }