public async Task <IActionResult> Delete(int id)
        {
            Category category;

            //using (_db)
            //{
            category = await _db.Categories.FindAsync(id);

            _db.Remove(category);
            await _db.SaveChangesAsync();

            //}
            return(RedirectToAction(nameof(List)));
        }
Esempio n. 2
0
        public async Task <IActionResult> DeleteReview(int id)
        {
            try
            {
                Comment comment = await _db.Comments.Where(c => c.Id == id).Include(c => c.User).FirstOrDefaultAsync();

                _db.Remove(comment);
                await _db.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception exp)
            {
                ModelState.AddModelError("", exp.Message);
                return(RedirectToAction(nameof(DocumentDesc)));
            }
        }
        public async Task <IActionResult> Delete(int id)
        {
            Document doc;

            //using (_db)
            //{
            doc = await _db.Documents.Include(x => x.Advocate).Where(d => d.Id == id).FirstOrDefaultAsync();

            if (doc != null)
            {
                string path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "uploads", doc.FileName);
                if (System.IO.File.Exists(path))
                {
                    System.IO.File.Delete(path);
                }
                _db.Remove(doc);
            }
            await _db.SaveChangesAsync();

            //}
            return(RedirectToAction(nameof(List)));
        }