public static List <SharedNotes> Distinct(List <SharedNotes> sharedNotes) { if (sharedNotes.Count == 0) { return(sharedNotes); } List <SharedNotes> newList = new List <SharedNotes> { sharedNotes.First() }; SharedNotes previousNote = newList.First(); IComparer <SharedNotes> comparer = new NotesComparer(); foreach (var note in sharedNotes) { if (comparer.Compare(note, previousNote) == 0) { previousNote.Shared_To_UserId.Add(note.Shared_To); } else { note.Shared_To_UserId.Add(note.Shared_To); newList.Add(note); previousNote = newList.Last(); } } return(newList); }
public async Task <List <SharedNotes> > GetUserNotes(string user) { try { int user_id = await GetUserId(user); List <SharedNotes> sharedNotes = await(from shares in dbModel.DbSetShares join note in dbModel.DbSetNotes on shares.Note_Id equals note.Note_Id where (note.User_Id == user_id) orderby note.Timestamp ascending select new SharedNotes { Note_Id = note.Note_Id, Note_Header = note.Header, Note_Content = note.Content, Note_Timestamp = note.Timestamp, Owner_Id = note.User_Id, Shared_To = shares.User_Id } ).ToListAsync(); SharedNotes.Sort(sharedNotes); return(sharedNotes); } catch (Exception e) { throw new Exception("Error occured on database query", e); } }