public void DeletePostCategory(int id) { var postsCategories = _context.PostsCategory .Where(x => x.Id == id) .ToList(); //delete photos....? for (int i = 0; i < postsCategories.Count; i++) { _context.Remove(postsCategories[i]); _context.SaveChanges(); } }
public int DeletePhotoPerPost(int photoId) { try { var photo = _context.PostsPhoto.Where(x => x.PhotoId == photoId).FirstOrDefault(); var postId = photo.PostId; _context.Remove(photo); _context.SaveChanges(); return(postId); } catch (Exception) { throw; } }
//Delete photo public IActionResult DeletePhoto(int id) { try { var photo = _context.Photo.Find(id); //deleting from postsPhoto var postId = _photoService.DeletePhotoPerPost(id); _context.Remove(photo); _context.SaveChanges(); return(RedirectToAction("ViewAllPhotos", new { id = postId })); } catch (Exception ex) { throw ex; } }
//Delete Category public IActionResult DeleteCategory(int id) { try { var isUsed = _categoryService.IsCategoryUsed(id); if (!isUsed) { var deleteCat = _context.Category.Find(id); _context.Remove(deleteCat); _context.SaveChanges(); } return(RedirectToAction("Index")); } catch (Exception ex) { throw ex; } }