private string GenerateData(int count) { var context = new NotesContext(App.StoreConnectionString); var categories = new List <ICategory>(); var rng = new Random(); for (int i = 0; i < count / 10; i++) { var category = context.Categories.Create(); category.Label = String.Format("Generated Category #{0}", i + 1); categories.Add(category); } int catCount = categories.Count; for (int i = 0; i < count; i++) { var category = categories[rng.Next(catCount)]; var note = context.Notes.Create(); note.Category = category; note.Label = "Note " + DateTime.Now.Ticks; note.Content = "Lorem ipsum etc etc etc."; } context.SaveChanges(); return(categories[rng.Next(count / 10)].CategoryId); }
public NotesController(ILogger <NotesController> logger, NotesContext context, UserApiClient userApiClient) { _logger = logger; _context = context; _userApiClient = userApiClient; _context.Database.EnsureCreated(); }
public ActionResult DeleteNote(int id) { using (NotesContext context = new NotesContext()) { return(View(context.Notes.Where(x => x.Id == id).FirstOrDefault())); } }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override void OnLaunched(LaunchActivatedEventArgs e) { using (var context = new NotesContext()) { context.Database.Migrate(); } // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (!(Window.Current.Content is Frame rootFrame)) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); rootFrame.NavigationFailed += OnNavigationFailed; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: Load state from previously suspended application } // Place the frame in the current Window Window.Current.Content = rootFrame; } if (e.PrelaunchActivated == false) { if (rootFrame.Content == null) { rootFrame.Navigate(typeof(MainPage), e.Arguments); } // Ensure the current window is active Window.Current.Activate(); } }
public IEnumerable <ToDo> GetAllToDos() { using (var dbContext = new NotesContext()) { return(dbContext.ToDos.ToList()); } }
public void Create_WritesToDB_HandwrittenTextStateIsPending(string DbName) { // Arrange var options = Initialize(DbName); int noteId = 0; // Act using (var context = new NotesContext(options)) { var service = new NoteService(context); noteId = service.Add(new Note() { Title = "Test note", HandwrittenText = new HandwrittenText() { Image = new byte[8] } }).Id; } // Assert using (var context = new NotesContext(options)) { var service = new NoteService(context); var note = service.GetById(noteId); Assert.AreEqual(State.Pending, note.HandwrittenText.State); } }
public void Delete_EntityDoesExist_ReturnsTrue(string DbName) { // Arrange var options = Initialize(DbName); var note = new Note() { Title = "Test Note" }; using (var context = new NotesContext(options)) { var service = new NoteService(context); note = service.Add(note); } // Act using (var context = new NotesContext(options)) { var service = new NoteService(context); var result = service.Delete(note.Id); // Assert Assert.True(result); } }
public void Update_EntityDoesNotExist_ReturnsTrueAndCreatesEntity(string DbName) { // Arrange var options = Initialize(DbName); var id = 1; var note = new Note() { Title = "Test Note" }; // Act using (var context = new NotesContext(options)) { var service = new NoteService(context); var result = service.Update(1, note); // Assert Assert.False(result); } using (var context = new NotesContext(options)) { var service = new NoteService(context); var fromDb = service.GetById(id); // Assert Assert.NotNull(fromDb); } }
public void GetById_EntryDoesExist_ReturnsNote(string DbName) { // Arrange var options = Initialize(DbName); var note = new Note() { Title = "Test Note" }; // Act using (var context = new NotesContext(options)) { var service = new NoteService(context); note = service.Add(note); } using (var context = new NotesContext(options)) { var service = new NoteService(context); var noteFromDb = service.GetById(note.Id); //Assert Assert.NotNull(noteFromDb); Assert.IsInstanceOf <Note>(noteFromDb); } }
public void GetAll_HasEntries_ReturnsListOfNotes(string DbName) { // Arrange var options = Initialize(DbName); using (var context = new NotesContext(options)) { var service = new NoteService(context); service.Add(new Note() { Title = "Test note", HandwrittenText = new HandwrittenText() { Image = new byte[8] } }); } // Act var result = new List <Note>(); using (var context = new NotesContext(options)) { var service = new NoteService(context); result = service.GetAll() as List <Note>; } // Assert Assert.IsInstanceOf <List <Note> >(result); Assert.IsNotEmpty(result); }
public static User GetUserByLogin(string login) { using (var context = new NotesContext()) { return(context.Users.Include(u => u.Notes).FirstOrDefault(u => u.Login == login)); } }
public async Task <IEnumerable <ToDo> > GetAllToDos() { using (var dbContext = new NotesContext()) { return(await dbContext.ToDos.ToListAsync()); } }
public static User GetUserByGuid(Guid guid) { using (var context = new NotesContext()) { return(context.Users.Include(u => u.Notes).FirstOrDefault(u => u.Guid == guid)); } }
public static List <User> GetAllUsers(Guid noteGuid) { using (var context = new NotesContext()) { return(context.Users.Where(u => u.Notes.All(r => r.Guid != noteGuid)).ToList()); } }
public Notes Get(int id) { using (notesContext = new NotesContext()) { return(notesContext.Notes.Find(id)); } }
public static List <Note> GetAllNotes(Guid userGuid) { using (var context = new NotesContext()) { return(context.Notes.Where(u => u.User.Guid == userGuid).ToList()); } }
public List <Notes> GetAll() { using (notesContext = new NotesContext()) { return(notesContext.Notes.ToList()); } }
private void NewCommand_Executed(object sender, ExecutedRoutedEventArgs e) { var item = treeView.SelectedItem; if (item is DataAccess.Table) { var popup = new NewStack(((DataAccess.Table)item).TableID); Stack stack; if (popup.ShowDialog().GetValueOrDefault()) { stack = popup.Stack; } else { return; } using (var db = new NotesContext()) { db.Stacks.Add(stack); db.SaveChanges(); } treeView.Items.Refresh(); treeView.UpdateLayout(); } }
public static Note GetNoteById(Guid noteGuid) { using (var context = new NotesContext()) { return(context.Notes.FirstOrDefault(u => u.Guid == noteGuid)); } }
public static bool UserExists(string login) { using (var context = new NotesContext()) { return(context.Users.Any(u => u.Login == login)); } }
public NoteDetailsForm(object dataSource, NotesContext context) { InitializeComponent(); noteBindingSource.DataSource = dataSource; noteDetails1.Context = context; noteDetails1.DataSource = dataSource; }
public IEnumerable <Note> GetAllNotes() { using (var dbContext = new NotesContext()) { return(dbContext.Notes.ToList()); } }
public static void SaveNote(Note note) { using (var context = new NotesContext()) { context.Entry(note).State = EntityState.Modified; context.SaveChanges(); } }
public static void AddUser(User user) { using (var context = new NotesContext()) { context.Users.Add(user); context.SaveChanges(); } }
public MainViewModel() { using (var db = new NotesContext()) { db.Tables.Include("Stacks.Books.Pages").Load(); Tables = db.Tables.Local; } }
public void DeleteTodo(ToDo toDo) { using (var dbContext = new NotesContext()) { dbContext.Remove(toDo); dbContext.SaveChanges(); } }
public void Add(Notes notes) { using (notesContext = new NotesContext()) { notesContext.Notes.Add(notes); notesContext.SaveChanges(); } }
public async Task DeleteTodoAsync(Todo todo) { using (var dbContext = new NotesContext()) { dbContext.Remove(todo); await dbContext.SaveChangesAsync().ConfigureAwait(false); } }
public ToDo GetTodo(int id) { using (var dbContext = new NotesContext()) { var toDo = dbContext.ToDos.Find(id); return(toDo); } }
static void Main(string[] args) { var context = new NotesContext(); HttpServer server = new HttpServer(8081, RouteTables.Routes); MvcEngine.Run(server); }
public UserRepository() { _dbContext = new NotesContext(); }
public NoteRepository(NotesContext dbContext) { _dbContext = dbContext; }
public UnitOfWork() { _dbContext = new NotesContext(); _transaction = new TransactionScope(); }