public void UpdateStudentNote(Student student, Przedmiot lecture, Ocena noteTemp, Ocena updatedNote) { if (student != null && lecture != null && noteTemp != null && updatedNote != null) { //Prepare Ocena field float wartoscOceny = updatedNote.Wartosc; DateTime time = updatedNote.DataWystawienia; updatedNote = noteTemp; if (time == null) { updatedNote.DataWystawienia = DateTime.Now; } else { updatedNote.DataWystawienia = time; } updatedNote.Wartosc = wartoscOceny; //Replace in Oceny (only, student store objectid note ) MongoDBContext.Oceny.ReplaceOne(ocenyObj => ocenyObj.Id == updatedNote.Id, updatedNote, new UpdateOptions { IsUpsert = true }); } }
public void DeleteNote(Ocena note) { if (note != null) { Ocena ocena = Notes.Find(noteObj => noteObj.Id == note.Id); if (ocena != null) { var indexFoundedNotes = Notes.IndexOf(ocena); Notes.RemoveAt(indexFoundedNotes); } } }
public void DeleteStudentNote(Student student, Przedmiot lecture, Ocena note) { if (student != null && lecture != null && note != null) { Ocena ocena = Notes.Find(noteObj => noteObj.Id == note.Id && student.Indeks == note.IdStudent && lecture.Id == note.IdPrzedmiot); if (ocena != null) { var indexFoundedNotes = Notes.IndexOf(ocena); Notes.RemoveAt(indexFoundedNotes); } } }
public void AddNote(Ocena note, Student student) { int indexStudent = -1; if (note != null && student != null) { indexStudent = Students.IndexOf(student); if (indexStudent > -1) { Students[indexStudent].Oceny.Add(note); } note.Id = generateUniqueNoteID(); Notes.Add(note); } }
public bool UpdateNote(Ocena updatedNote) { bool IsNoteUpdated = false; var noteToReplace = Notes.Find(noteObj => noteObj.Id == updatedNote.Id); if (noteToReplace != null) { var indexOfReplacedNote = Notes.IndexOf(noteToReplace); if (indexOfReplacedNote >= 0) { Notes[indexOfReplacedNote] = updatedNote; IsNoteUpdated = true; } } return(IsNoteUpdated); }
public void DeleteStudentNote(Student student, Przedmiot lecture, Ocena note) { if (student != null && lecture != null && note != null) { //Delete from Oceny MongoDBContext.Oceny.DeleteMany(ocenaObj => ocenaObj.Id == note.Id && ocenaObj.IdPrzedmiot == note.IdPrzedmiot && ocenaObj.IdStudent == note.IdStudent); //Delete from concrete student student.Oceny.RemoveAll(ocenaObj => ocenaObj == note.Id); //Replace modified student MongoDBContext.Studenci.ReplaceOne(studentObj => studentObj.Id == student.Id, student, new UpdateOptions { IsUpsert = true }); } }
public void UpdateStudentNote(Student student, Przedmiot lecture, Ocena note) { var studentFounded = Students.Find(studentObj => studentObj.Indeks == student.Indeks); var lectureFounded = Lectures.Find(lectureObj => lectureObj.Id == lecture.Id); var noteFounded = Notes.Find(lectureObj => lectureObj.Id == note.Id); if (studentFounded != null && lectureFounded != null && noteFounded != null) { int indexStudent = Students.IndexOf(studentFounded); int indexLecture = Lectures.IndexOf(lectureFounded); int indexNote = Notes.IndexOf(noteFounded); note.IdStudent = student.Indeks; note.IdPrzedmiot = lecture.Id; note.DataWystawienia = DateTime.Now; //Students[indexStudent].Oceny.Add(note); Notes.RemoveAt(indexNote); Notes.Insert(indexNote, note); //studentExisted.Przedmioty.Add(lectureExisted); } }
public void AddNoteStudentFromLecture(Student studentExisted, Przedmiot lectureExisted, Ocena note) { if (studentExisted != null && lectureExisted != null && note != null) { //Find last added Ocena long ocenyIndex = 0; Ocena lastAddedNote = MongoDBContext.Oceny.Find(_ => true).ToList().OrderByDescending(ocenaObj => ocenaObj.IdOceny).FirstOrDefault(); if (lastAddedNote != null) { ocenyIndex = lastAddedNote.IdOceny; ocenyIndex++; } //Prepare Ocena field note.IdOceny = (int)ocenyIndex; note.IdPrzedmiotu = lectureExisted.IdPrzedmiotu; note.Indeks = studentExisted.Indeks; note.IdStudent = studentExisted.Id; note.IdPrzedmiot = lectureExisted.Id; if (note.DataWystawienia == null) { note.DataWystawienia = DateTime.Now; } //Add to Oceny MongoDBContext.Oceny.InsertOne(note); //Add to concrete Student Oceny var ocenaLastAdded = MongoDBContext.Oceny.Find(_ => true).ToList().OrderByDescending(ocenaObj => ocenaObj.IdOceny).FirstOrDefault(); studentExisted.Oceny.Add(ocenaLastAdded.Id); //Replace old Student data to new MongoDBContext.Studenci.ReplaceOne(studentObj => studentObj.Id == studentExisted.Id, studentExisted, new UpdateOptions { IsUpsert = true }); } }
public void AddNoteStudentFromLecture(Student studentExisted, Przedmiot lectureExisted, Ocena note) { var studentFounded = Students.Find(studentObj => studentObj.Indeks == studentExisted.Indeks); var lectureFounded = Lectures.Find(lectureObj => lectureObj.Id == lectureExisted.Id); if (studentExisted != null && lectureExisted != null && note != null) { int indexStudent = Students.IndexOf(studentFounded); int indexLecture = Lectures.IndexOf(lectureFounded); note.Id = generateUniqueNoteID(); note.IdStudent = studentExisted.Indeks; note.IdPrzedmiot = lectureExisted.Id; note.DataWystawienia = DateTime.Now; Students[indexStudent].Oceny.Add(note); Notes.Add(note); //studentExisted.Przedmioty.Add(lectureExisted); } }
public void DeleteNote(Student student, Przedmiot lecture, Ocena note) { DeleteStudentNote(student, lecture, note); }
public void UpdateNote(Przedmiot lecture, Student student, Ocena note, Ocena noteFromBody) { UpdateStudentNote(student, lecture, note, noteFromBody); }