Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void Remove<TObject>(TObject @object) where TObject : class
- {
- if (@object is Album album)
- {
- if (album.Pictures.Any()) Remove(album.Pictures.ToList());
- _context.Albums.Attach(album);
- _context.Entry(album).State = EntityState.Deleted;
- }
- else if (@object is Photo photo)
- {
- _context.Photos.Attach(photo);
- _context.Entry(photo).State = EntityState.Deleted;
- }else if(@object is Author author)
- {
- _context.Authors.Attach(author);
- _context.Entry(author).State = EntityState.Deleted;
- }
- else if(@object is Genre genre)
- {
- _context.Genres.Attach(genre);
- _context.Entry(genre).State = EntityState.Deleted;
- }
- else if(@object is Filter filter)
- {
- _context.Filters.Attach(filter);
- _context.Entry(filter).State = EntityState.Deleted;
- }
- else if(@object is IEnumerable<Photo> photos)
- {
- foreach (Photo p in photos)
- {
- _context.Photos.Attach(p);
- _context.Entry(p).State = EntityState.Deleted;
- }
- }else if(@object is IEnumerable<Album> albums)
- {
- foreach (Album a in albums)
- {
- if (a.Pictures.Any()) Remove(a.Pictures);
- _context.Albums.Attach(a);
- _context.Entry(a).State = EntityState.Deleted;
- }
- }
- else if(@object is IEnumerable<Author> authors)
- {
- foreach (Author auth in authors)
- {
- _context.Authors.Attach(auth);
- _context.Entry(auth).State = EntityState.Deleted;
- }
- }
- else if(@object is IEnumerable<Filter> filters)
- {
- foreach (Filter fil in filters)
- {
- _context.Filters.Attach(fil);
- _context.Entry(fil).State = EntityState.Deleted;
- }
- }
- else if(@object is IEnumerable<Genre> genres)
- {
- foreach (Genre gen in genres)
- {
- _context.Genres.Attach(gen);
- _context.Entry(gen).State = EntityState.Deleted;
- }
- }
- else
- {
- PhotoAlbumTools.UnknownEntity(@object);
- return;
- }
- _context.SaveChanges();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement