示例#1
0
        public virtual ActionResult ListCategory(string slug, int page, int size)
        {
            var photos = _context.FindPhotosByCategorySlug(slug, page, size);

            var model = MapToViewModel(photos);

            return(PartialView(Views.List, model));
        }
        public virtual ActionResult Delete(int id)
        {
            var category = _context.FindById <CategoryModel>(id);

            if (category == null)
            {
                return(HttpNotFound());
            }

            var photos = _context.FindPhotosByCategorySlug(category.Slug, 1, int.MaxValue);

            foreach (var photo in photos)
            {
                var userPhotoActions = _context.FindUserPhotoActionsByPhotoId(photo.PhotoId);
                var comments         = _context.FindCommentsByPhotoId(photo.PhotoId);

                foreach (var userPhotoAction in userPhotoActions)
                {
                    _context.Delete(userPhotoAction);
                    _context.SaveChanges();
                }

                foreach (var comment in comments)
                {
                    _context.Delete(comment);
                    _context.SaveChanges();
                }

                _context.Delete(photo);
                _context.SaveChanges();
            }

            _context.Delete(category);
            _context.SaveChanges();

            return(RedirectToAction(T4Routes.Category.Manage()));
        }