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);
        }
Beispiel #2
0
 public NotesController(ILogger <NotesController> logger, NotesContext context, UserApiClient userApiClient)
 {
     _logger        = logger;
     _context       = context;
     _userApiClient = userApiClient;
     _context.Database.EnsureCreated();
 }
Beispiel #3
0
 public ActionResult DeleteNote(int id)
 {
     using (NotesContext context = new NotesContext())
     {
         return(View(context.Notes.Where(x => x.Id == id).FirstOrDefault()));
     }
 }
Beispiel #4
0
        /// <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();
            }
        }
Beispiel #5
0
 public IEnumerable <ToDo> GetAllToDos()
 {
     using (var dbContext = new NotesContext())
     {
         return(dbContext.ToDos.ToList());
     }
 }
Beispiel #6
0
        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);
            }
        }
Beispiel #7
0
        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);
            }
        }
Beispiel #8
0
        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);
            }
        }
Beispiel #9
0
        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);
            }
        }
Beispiel #10
0
        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);
        }
Beispiel #11
0
 public static User GetUserByLogin(string login)
 {
     using (var context = new NotesContext())
     {
         return(context.Users.Include(u => u.Notes).FirstOrDefault(u => u.Login == login));
     }
 }
Beispiel #12
0
 public async Task <IEnumerable <ToDo> > GetAllToDos()
 {
     using (var dbContext = new NotesContext())
     {
         return(await dbContext.ToDos.ToListAsync());
     }
 }
Beispiel #13
0
 public static User GetUserByGuid(Guid guid)
 {
     using (var context = new NotesContext())
     {
         return(context.Users.Include(u => u.Notes).FirstOrDefault(u => u.Guid == guid));
     }
 }
Beispiel #14
0
 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());
     }
 }
Beispiel #15
0
 public Notes Get(int id)
 {
     using (notesContext = new NotesContext())
     {
         return(notesContext.Notes.Find(id));
     }
 }
Beispiel #16
0
 public static List <Note> GetAllNotes(Guid userGuid)
 {
     using (var context = new NotesContext())
     {
         return(context.Notes.Where(u => u.User.Guid == userGuid).ToList());
     }
 }
Beispiel #17
0
 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();
            }
        }
Beispiel #19
0
 public static Note GetNoteById(Guid noteGuid)
 {
     using (var context = new NotesContext())
     {
         return(context.Notes.FirstOrDefault(u => u.Guid == noteGuid));
     }
 }
Beispiel #20
0
 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;
 }
Beispiel #22
0
 public IEnumerable <Note> GetAllNotes()
 {
     using (var dbContext = new NotesContext())
     {
         return(dbContext.Notes.ToList());
     }
 }
Beispiel #23
0
 public static void SaveNote(Note note)
 {
     using (var context = new NotesContext())
     {
         context.Entry(note).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Beispiel #24
0
 public static void AddUser(User user)
 {
     using (var context = new NotesContext())
     {
         context.Users.Add(user);
         context.SaveChanges();
     }
 }
Beispiel #25
0
 public MainViewModel()
 {
     using (var db = new NotesContext())
     {
         db.Tables.Include("Stacks.Books.Pages").Load();
         Tables = db.Tables.Local;
     }
 }
Beispiel #26
0
 public void DeleteTodo(ToDo toDo)
 {
     using (var dbContext = new NotesContext())
     {
         dbContext.Remove(toDo);
         dbContext.SaveChanges();
     }
 }
Beispiel #27
0
 public void Add(Notes notes)
 {
     using (notesContext = new NotesContext())
     {
         notesContext.Notes.Add(notes);
         notesContext.SaveChanges();
     }
 }
Beispiel #28
0
 public async Task DeleteTodoAsync(Todo todo)
 {
     using (var dbContext = new NotesContext())
     {
         dbContext.Remove(todo);
         await dbContext.SaveChangesAsync().ConfigureAwait(false);
     }
 }
Beispiel #29
0
 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);
        }
Beispiel #31
0
 public UserRepository()
 {
     _dbContext = new NotesContext();
 }
Beispiel #32
0
 public NoteRepository(NotesContext dbContext)
 {
     _dbContext = dbContext;
 }
Beispiel #33
0
 public UnitOfWork()
 {
     _dbContext = new NotesContext();
     _transaction = new TransactionScope();
 }