public override int Delete(Category category) { NoteManager noteManager = new NoteManager(); LikedManager likedManager = new LikedManager(); CommentManager commentManager = new CommentManager(); //kategoride ilişkili notlar silincek foreach (Note note in category.Notes.ToList()) { //kategoride ilişkili beğeni silincek foreach (Liked like in note.Likes.ToList()) { likedManager.Delete(like); } //kategoride ilişkili yorumlar silincek foreach (Comment comment in note.Comments.ToList()) { commentManager.Delete(comment); } noteManager.Delete(note); } return(base.Delete(category)); }
public override int Delete(Category category) { NoteManager noteManager = new NoteManager(); LikedManager likedManager = new LikedManager(); CommentManager commentManager = new CommentManager(); // Kategori ile ilişkili notların silinmesi gerekiyor. foreach (Note note in category.Notes.ToList()) { // Note ile ilişikili like'ların silinmesi. foreach (Liked like in note.Likes.ToList()) { likedManager.Delete(like); } // Note ile ilişkili comment'lerin silinmesi foreach (Comment comment in note.Comments.ToList()) { commentManager.Delete(comment); } noteManager.Delete(note); } return(base.Delete(category)); }
public override int Delete(Category category) { NoteManager noteManager = new NoteManager(); LikedManager likedManager = new LikedManager(); CommentManager commentManager = new CommentManager(); //Deleting Notes which relational with Category foreach (Note note in category.Notes.ToList()) { //Deleting Likes which relational with Notes foreach (Liked like in note.Likes.ToList()) { likedManager.Delete(like); } //Deleting comments which relational with Notes foreach (Comment comment in note.Comments.ToList()) { commentManager.Delete(comment); } noteManager.Delete(note); } return(base.Delete(category)); }
// Bir kategor silindiği zaman ona bağlı olan şeyleride silmemzi lazım bunun için ise delete methodunu eziyoruz public override int Delete(Category category)//ManagerBase içindeki delete methodunu override ile eziyoruz { NoteManager noteManager = new NoteManager(); LikedManager liked = new LikedManager(); CommentManager comment = new CommentManager(); //Kategori ile işkişi notlarını silinmesi gerekiyor foreach (Note note in category.Notes.ToList())//notların içinde dönerek onları delete edicez { //note ile ilişkili like ların silinmesi foreach (Liked like in note.Likes.ToList()) { liked.Delete(like); } //Notu ile ilişkili commentlerin silinmesi foreach (Comment commet in note.Comments.ToList()) { comment.Delete(commet); } noteManager.Delete(note); } return(base.Delete(category)); }
public override int Delete(Category category) { //1)Yöntem: Kategori ile ilişkili notların silinmesi gerekiyor. // Burada override edildi çünkü uyguulamalar arası köprü gören kısım burası burda olması daha doğru //2)Yöntem: Dbtarafında Database Diagramda oluşan yapı üzerinde ilişkili okların üerini tıklayarak properties tarafıdan delete action'ı cascade et. //3) Yöntem: Databese in oluştuğu yer (DatabaseContext) buraya OnModelCreating override ederek FluentApi şeklinde oluşturulabilir. NoteManager noteManager = new NoteManager(); LikedManager likedManager = new LikedManager(); CommentManager commentManager = new CommentManager(); foreach (Note note in category.Notes.ToList()) { foreach (Liked like in note.Likes.ToList()) { likedManager.Delete(like); } foreach (Comment comment in note.Comments.ToList()) { commentManager.Delete(comment); } noteManager.Delete(note); } return(base.Delete(category)); }
public MessageResult <ENote> RemoveNoteById(int id) { LikeManager likeManager = new LikeManager(); CommentManager commentManager = new CommentManager(); MessageResult <ENote> res = new MessageResult <ENote>(); res.Result = Find(x => x.Id == id); if (res.Result != null) { foreach (EComment item in res.Result.Comments.ToList()) { commentManager.Delete(item); } foreach (ELiked like in res.Result.Likes.ToList()) { likeManager.Delete(like); } if (Delete(res.Result) == 0) { res.AddError(ErrorMessageCodes.CategoryCouldNotRemove, "Note could not be deleted."); } return(res); } else { res.AddError(ErrorMessageCodes.NoteCouldNotFind, "Note could not find."); return(res); } }
public MessageResult <ECategory> RemoveCategoryById(int id) { NoteManager noteManager = new NoteManager(); LikeManager likeManager = new LikeManager(); CommentManager commentManager = new CommentManager(); MessageResult <ECategory> res = new MessageResult <ECategory>(); res.Result = Find(x => x.Id == id); if (res.Result != null) { //delete foreach (ENote note in res.Result.Notes.ToList()) { //delete like foreach (ELiked like in note.Likes.ToList()) { likeManager.Delete(like); } //comment delete foreach (EComment comment in note.Comments.ToList()) { commentManager.Delete(comment); } //note delete noteManager.Delete(note); } if (Delete(res.Result) == 0) { res.AddError(ErrorMessageCodes.CategoryCouldNotRemove, "Category could not be deleted."); } return(res); } else { res.AddError(ErrorMessageCodes.UserCouldNotFind, "User could not find."); } return(res); }