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...");
        }
Example #2
0
        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"));
        }
Example #4
0
        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"));
        }
Example #5
0
        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();
 }
Example #7
0
 public void Delete(int id)
 {
     db.Remove(db.Books.Find(id));
 }