@@ -6,40 +6,27 @@ namespace winrt::ReactNativeNotes::implementation
66{
77 void Repository::Create ( NoteModel& note ) noexcept
88 {
9- note.ID ( static_cast <unsigned int >(notes.size ()) );
109 notes.push_back ( note );
1110 }
1211
13- NoteModel Repository::Read ( const unsigned int ID ) const noexcept
12+ NoteModel Repository::Read ( const int index ) const noexcept
1413 {
15- for ( auto it = notes.cbegin (); it != notes. cend (); ++it )
14+ if ( index < notes.size () )
1615 {
17- if ( it->ID () == ID )
18- return it.operator *();
16+ return notes.at ( index );
1917 }
20- return NoteModel ();
21- }
22-
23- NoteModel Repository::Read ( const int index ) const noexcept
24- {
25- if ( index >= notes.size () )
26- return NoteModel ();
2718 else
28- return notes.at (index);
29- }
30-
31- void Repository::Update ( const NoteModel& note ) noexcept
32- {
33- if ( note.ID () < notes.size () )
3419 {
35- notes[note. ID ()] = note ;
20+ return NoteModel () ;
3621 }
3722 }
3823
39- void Repository::Delete ( const unsigned int ID ) noexcept
24+ void Repository::Update ( const NoteModel& note, const unsigned int & index ) noexcept
4025 {
41- auto it = std::find ( notes.cbegin (), notes.cend (), Read (ID) );
42- notes.erase ( it );
26+ if ( index < notes.size () )
27+ {
28+ notes[index] = note;
29+ }
4330 }
4431
4532 void Repository::Delete ( const int index ) noexcept
@@ -52,10 +39,6 @@ namespace winrt::ReactNativeNotes::implementation
5239 return notes.size ();
5340 }
5441
55- const bool Repository::Exists ( const unsigned int ID ) const noexcept
56- {
57- return std::find_if ( notes.cbegin (), notes.cend (), [=]( const NoteModel& n )->bool { return n.ID () == ID; } ) != notes.cend ();
58- }
5942 const bool Repository::Exists ( const int index ) const noexcept
6043 {
6144 return index < notes.size ();
0 commit comments