public void Login(Window p) { NetVideoEntities db = new NetVideoEntities(); String passEncode = ""; if (Password != null) { passEncode = CreateMD5(Base64Encode(Password)); } var acc = db.Accounts.Where(x => x.Email == Email && x.Password == passEncode).FirstOrDefault(); if (acc != null) { MainWindow main = new MainWindow(acc.Id); p.Hide(); main.ShowDialog(); if (Application.Current != null) { p.Show(); } } else { MessageBox.Show("Sorry, we can't find an account with this email address. Please try again!"); } }
void ExecuteChangePassword() { string oldPasswordEncode = CreateMD5(Base64Encode(OldPassword)); string newPasswordEncode = CreateMD5(Base64Encode(NewPassword)); string repeatNewPasswordEncode = CreateMD5(Base64Encode(RepeatNewPassword)); NetVideoEntities db = new NetVideoEntities(); Account acc = db.Accounts.FirstOrDefault(a => a.Id == IdAccount); if (acc.Password != oldPasswordEncode) { MessageBox.Show("Incorrect current password!"); return; } if (NewPassword != RepeatNewPassword) { MessageBox.Show("New password and repeat new password do not match!"); return; } acc.Password = newPasswordEncode; db.SaveChanges(); MessageBox.Show("Change password successed!"); }
public void BindingDetail(int id, UserControl nameUC) { NetVideoEntities db = new NetVideoEntities(); DetaiVideoUC uc = nameUC as DetaiVideoUC; VideoInfo videoInfo = db.VideoInfoes.Where(x => x.Id == id).FirstOrDefault(); uc.DataContext = videoInfo; this.ListGenre = videoInfo.VideoGenres.ToList(); StackPanel tb = (StackPanel)uc.FindName("tbGenres"); tb.DataContext = this; }
public CusInfoViewModel() { UpdateCommand = new RelayCommand <UserControl>((p) => { return(CanExecuteUpdate(p)); }, (p) => { NetVideoEntities db = new NetVideoEntities(); CustomerInfo cus = db.CustomerInfoes.SingleOrDefault(c => c.AccountId == Id); cus.FirstName = FirstName; cus.LastName = LastName; cus.CardNumber = CardNumber; cus.CardExpirationDate = null;//ExpirationDate; cus.SecurityCode = SecurityCode; db.SaveChanges(); MessageBox.Show("Update successed!"); }); }
private void BtnMyList_Click(object sender, RoutedEventArgs e) { Window wd = GetWindow(); CollapseAll(wd); int idAccount = int.Parse((sender as Button).Tag.ToString()); NetVideoEntities db = new NetVideoEntities(); ListVideo2ViewModel lv = new ListVideo2ViewModel(); lv.ListVideo = db.VideoInfoes.Where(x => x.Accounts.Select(z => z.Id).Contains(idAccount)).ToList(); lv.TotalPage = (int)Math.Ceiling(lv.ListVideo.Count() * 1.0 / lv.PageSize); lv.ListVideoShow = new ObservableCollection <VideoInfo>(lv.ListVideo.OrderBy(l => l.Id).Skip((lv.CurPage - 1) * lv.PageSize).Take(lv.PageSize).ToList()); UserControl uc2 = (UserControl)wd.FindName("list2"); uc2.DataContext = lv; uc2.Visibility = Visibility.Visible; }
public override ValidationResult Validate(object value, CultureInfo cultureInfo) { var vr = new ValidationResult(true, null); bool b = Regex.IsMatch(value.ToString(), @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"); if (!b) { vr = new ValidationResult(false, "Please enter a valid email."); } NetVideoEntities db = new NetVideoEntities(); var accCount = db.Accounts.Where(x => x.Email == value.ToString()).Count(); if (accCount > 0) { vr = new ValidationResult(false, "Email address already in use."); } return(vr); }
private void StackPanel_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e) { NetVideoEntities db = new NetVideoEntities(); StackPanel s = sender as StackPanel; StackPanel stack = (StackPanel)s.FindName("stack"); if (oldTag != null) { if (oldTag == stack.Tag.ToString()) { detail.Visibility = System.Windows.Visibility.Collapsed; oldTag = null; return; } } int id = int.Parse(stack.Tag.ToString()); DetailVideoViewModel d = new DetailVideoViewModel(); d.BindingDetail(id, detail); detail.Visibility = System.Windows.Visibility.Visible; oldTag = stack.Tag.ToString(); }
public ControlBarViewModel() { NetVideoEntities db = new NetVideoEntities(); CloseCommand = new RelayCommand <object>((p) => { return(true); }, (p) => { System.Windows.Application.Current.Shutdown(); }); CusInfoCommand = new RelayCommand <UserControl>((p) => { return(true); }, (p) => { db = new NetVideoEntities(); FrameworkElement wd = GetWindow(p); var window = wd as Window; if (window != null) { CollapseAll(window); CusInfoViewModel cf = new CusInfoViewModel(); CustomerInfo c = db.CustomerInfoes.Where(x => x.AccountId == IdAccount).FirstOrDefault(); if (c != null) { cf.Id = IdAccount; cf.FirstName = c.FirstName; cf.LastName = c.LastName; cf.CardNumber = c.CardNumber; cf.ExpirationDate = c.CardExpirationDate.ToString(); cf.SecurityCode = c.SecurityCode; } UserControl uc1 = (UserControl)wd.FindName("cusInfo"); uc1.DataContext = cf; uc1.Visibility = Visibility.Visible; } }); ChangePasswordCommand = new RelayCommand <UserControl>((p) => { return(true); }, (p) => { FrameworkElement wd = GetWindow(p); var window = wd as Window; if (window != null) { CollapseAll(window); ChangePasswordViewModel cp = new ChangePasswordViewModel(); cp.IdAccount = IdAccount; UserControl uc3 = (UserControl)wd.FindName("changePassword"); uc3.DataContext = cp; uc3.Visibility = Visibility.Visible; } }); LogoutCommand = new RelayCommand <UserControl>((p) => { return(p == null ? false : true); }, (p) => { FrameworkElement wd = GetWindow(p); var window = wd as Window; if (window != null) { window.Close(); } }); SearchCommand = new RelayCommand <UserControl>((p) => { return(true); }, (p) => { FrameworkElement wd = GetWindow(p); var window = wd as Window; if (window != null) { CollapseAll(window); ListVideo2ViewModel lv = new ListVideo2ViewModel(); lv.ListVideo = db.VideoInfoes.Where(v => v.Name.ToLower().Contains(KeyWords.ToLower())).ToList(); lv.TotalPage = (int)Math.Ceiling(lv.ListVideo.Count() * 1.0 / lv.PageSize); lv.ListVideoShow = new ObservableCollection <VideoInfo>(lv.ListVideo.OrderBy(l => l.Id).Skip((lv.CurPage - 1) * lv.PageSize).Take(lv.PageSize).ToList()); UserControl uc2 = (UserControl)wd.FindName("list2"); uc2.DataContext = lv; uc2.Visibility = Visibility.Visible; } }); MenuItems = db.VideoGenres.ToList(); }