/// <summary> /// Deletes the user label. /// </summary> /// <param name="userID">The user identifier.</param> /// <param name="labelID">The label identifier.</param> /// <returns></returns> public bool DeleteUserLabel(long userID, long labelID) { try { if (NotesDB.Labels.Any(N => N.UserId == userID && N.LabelId == labelID)) { NotesDB.Set <NoteLabel>(). RemoveIfExists(new NoteLabel { LabelId = labelID }); NotesDB.Set <Label>(). RemoveIfExists(new Label { LabelId = labelID }); NotesDB.SaveChanges(); return(true); } return(false); } catch (Exception) { throw; } }
/// <summary> /// Adds the user note. /// </summary> /// <param name="note">The note.</param> /// <returns></returns> public ResponseNoteModel AddUserNote(ResponseNoteModel note) { try { var NewNote = new Note { UserId = note.UserID, Title = note.Title, Text = note.Text, ReminderOn = note.ReminderOn, BackgroundColor = note.BackgroundColor, BackgroundImage = note.BackgroundImage, IsArchive = note.IsArchive, IsPin = note.IsPin, IsTrash = note.IsTrash, }; NotesDB.Notes.Add(NewNote); NotesDB.SaveChanges(); if (note.Labels != null) { note.Labels.ToList().ForEach(L => NotesDB.Set <Label>().AddIfNotExists(new Label { UserId = NewNote.UserId, LabelName = L }, x => x.LabelName.Equals(L))); NotesDB.SaveChanges(); note.Labels.ToList().ForEach(L => NotesDB.NoteLabels.Add( new NoteLabel { NoteId = NewNote.NoteId, LabelId = NotesDB.Labels.FirstOrDefault(a => a.LabelName == L).LabelId })); } if (note.Collaborators != null) { note.Collaborators.ToList().ForEach(C => NotesDB.Collaborators.Add( new Collaborator { UserId = NewNote.UserId, NoteId = NewNote.NoteId, CollaboratorEmail = C })); NotesDB.SaveChanges(); } var NewResponseNote = new ResponseNoteModel { UserID = (long)NewNote.UserId, NoteID = NewNote.NoteId, Title = NewNote.Title, Text = NewNote.Text, CreatedOn = NewNote.CreatedOn, ReminderOn = NewNote.ReminderOn, BackgroundColor = NewNote.BackgroundColor, BackgroundImage = NewNote.BackgroundImage, IsArchive = NewNote.IsArchive, IsPin = NewNote.IsPin, IsTrash = NewNote.IsTrash, Labels = NewNote.NoteLabels.Select(N => N.Label.LabelName).ToList(), Collaborators = NewNote.Collaborators.Select(C => C.CollaboratorEmail).ToList() }; return(NewResponseNote); } catch (Exception) { throw; } }
public virtual IEnumerable <T> GetAll() { return(_context.Set <T>().AsEnumerable()); }