예제 #1
0
        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();
            }
        }
예제 #2
0
        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;
            }
        }
예제 #3
0
        //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;
            }
        }
예제 #4
0
        //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;
            }
        }