Beispiel #1
0
        public void Initialize()
        {
            using var db = new SoPContext();
            //Remove users
            var userList = db.Users.ToList();

            db.Users.RemoveRange(userList);
            db.SaveChanges();

            //Add Admin User
            var adminUser = User.CreateNew("admin", "admin");

            db.Users.Add(adminUser);
            db.SaveChanges();
        }
Beispiel #2
0
        public void AddUser()
        {
            var user = User.CreateNew("testuser", "password");

            using var db = new SoPContext();
            db.Users.Add(user);
            db.SaveChanges();
        }
        public void Delete(int passwordEntryId)
        {
            using var context = new SoPContext();
            var pass = context.PasswordEntries.FirstOrDefault(pass => pass.Id == passwordEntryId);

            if (pass != null)
            {
                context.PasswordEntries.Remove(pass);
                context.SaveChanges();
            }
        }
Beispiel #4
0
        public void Delete(int categoryId)
        {
            using var context = new SoPContext();
            var cat = context.Categories.FirstOrDefault(cat => cat.Id == categoryId);

            if (cat != null)
            {
                context.Categories.Remove(cat);
                context.SaveChanges();
            }
        }
Beispiel #5
0
 public bool Create(User user)
 {
     try
     {
         using var dbContext = new SoPContext();
         dbContext.Users.Add(user);
         dbContext.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Beispiel #6
0
 public bool Create(Category category)
 {
     try
     {
         using var context = new SoPContext();
         context.Categories.Add(category);
         context.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Beispiel #7
0
        public void AddData()
        {
            using var db = new SoPContext();
            var dbUser = db.Users.FirstOrDefault(u => u.Username == "admin");
            var id     = 0;

            if (dbUser != null)
            {
                id = dbUser.Id;
            }
            else
            {
                var user = User.CreateNew("admin", "admin");
                id = db.Users.Add(user).Entity.Id;
            }
            var password1 = new PasswordEntry()
            {
                Description = "Password 1 for category 1",
                Password    = "******",
                Title       = "Password 1"
            };
            var password2 = new PasswordEntry()
            {
                Description = "Password 2 for category 1",
                Password    = "******",
                Title       = "Password 2"
            };
            var password3 = new PasswordEntry()
            {
                Description = "Password 3 for category 2",
                Password    = "******",
                Title       = "Password 3"
            };
            var cat1 = Category.CreateNew("TestCategory 1", "Category for testing 1", id);

            cat1.Passwords.Add(password1);
            cat1.Passwords.Add(password2);
            var cat2 = Category.CreateNew("TestCategory 2", "Category for testing 2", id);

            cat2.Passwords.Add(password3);
            db.Categories.Add(cat1);
            db.Categories.Add(cat2);
            db.SaveChanges();
        }
 public void Save(PasswordEntry passwordEntry)
 {
     using var context = new SoPContext();
     context.Update(passwordEntry);
     context.SaveChanges();
 }
Beispiel #9
0
 public void Save(Category category)
 {
     using var context = new SoPContext();
     context.Update(category);
     context.SaveChanges();
 }