예제 #1
0
 private void BtnSave_Click(object sender, RoutedEventArgs e)
 {
     if (!string.IsNullOrEmpty(txtName.Text) && !string.IsNullOrEmpty(txtLName.Text))
     {
         try
         {
             using (var db = new mydbContext())
             {
                 //var data = new tbl_Users
                 //{
                 //    Name = txtName.Text,
                 //    LName = txtLName.Text,
                 //    Profile = createThumb(imgProfile.Source as BitmapImage)
                 //};
                 //db.tbl_Users.Add(data);
                 //db.SaveChanges();
                 CallInsert(txtName.Text, txtLName.Text, createThumb(imgProfile.Source as BitmapImage));
                 MainWindow.main.showNotification(false, "Saved to Database");
             }
         }
         catch (Exception)
         {
             MainWindow.main.showNotification(true, "Error");
         }
     }
     else
     {
         MainWindow.main.showNotification(true, "Fill input");
     }
 }
예제 #2
0
 public void loadData()
 {
     using (var db = new mydbContext())
     {
         dgv.ItemsSource = db.tbl_Users.ToList();
     }
 }
예제 #3
0
        public async Task <List <tbl_Users> > GetData()
        {
            var db   = new mydbContext();
            var data = db.tbl_Users.ToListAsync();

            return(await data);
        }
예제 #4
0
 private void SearchBar_SearchStarted(object sender, HandyControl.Data.FunctionEventArgs <string> e)
 {
     using (var db = new mydbContext())
     {
         dgv.ItemsSource = db.tbl_Users.Where(x => x.NameX.Contains(txtSearch.Text) || x.LName.Contains(txtSearch.Text)).Select(x => x).ToList();
     }
 }
예제 #5
0
        public MainWindow()
        {
            InitializeComponent();
            main = this;
            var db = new mydbContext();

            db.Database.Migrate();
        }
예제 #6
0
 public void loadData()
 {
     using (var db = new mydbContext())
     {
         var data = db.tbl_Users.ToList();
         _initialData    = data;
         dgv.ItemsSource = data;
     }
 }
예제 #7
0
        public async Task <string> DeleteUser(int id)
        {
            var db     = new mydbContext();
            var delete = await db.tbl_Users.FindAsync(id);

            db.tbl_Users.Remove(delete);
            await db.SaveChangesAsync();

            return("deleted");
        }
예제 #8
0
        public async Task <string> UpdateUser(int id, string name, string lname, byte[] profile)
        {
            var db   = new mydbContext();
            var edit = await db.tbl_Users.FindAsync(id);

            edit.NameX   = name;
            edit.LName   = lname;
            edit.Profile = profile;
            await db.SaveChangesAsync();

            return("edited");
        }
예제 #9
0
        public async Task <string> InsertToUser(string name, string lname, byte[] profile)
        {
            var db   = new mydbContext();
            var data = new tbl_Users
            {
                NameX   = name,
                LName   = lname,
                Profile = profile
            };

            db.tbl_Users.Add(data);
            await db.SaveChangesAsync();

            return("user added");
        }