예제 #1
0
 static public void SaveChanges()
 {
     if (db != null)
     {
         db.SaveChanges();
     }
 }
예제 #2
0
 static public void SaveAndCloseProducts()
 {
     if (db != null)
     {
         db.SaveChanges();
         db.Dispose();
         db = null;
     }
 }
예제 #3
0
 static public void SaveAndCloseEmployees()
 {
     if (db != null)
     {
         db.SaveChanges();
         db.Dispose();
         db = null;
     }
 }
예제 #4
0
        /* Static boolean method to register new user from Login Form*/
        public static bool RegisterNewUser(int userID, string username, string password, string email)
        {
            if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password) || string.IsNullOrWhiteSpace(email))
            {
                MessageBox.Show("Va rugam completati toate campurile!", "Warning", MessageBoxButtons.OK);
                return(false);
            }

            using (var db = new GestiuneDBEntities())
            {
                var idFound       = db.Angajati.FirstOrDefault(b => b.AngajatID == userID);
                var idDuplicate   = db.Credentials.FirstOrDefault(c => c.AngajatID == userID);
                var usernameFound = db.Credentials.FirstOrDefault(a => a.Username == username);
                if (idFound != null)
                {
                    if (idDuplicate == null)
                    {
                        if (IsMailValid(email))
                        {
                            if (usernameFound == null)
                            {
                                Credentials credential = new Credentials();
                                credential.Username  = username;
                                credential.Password  = EncryptPassword(password, hashString);
                                credential.AngajatID = userID;
                                credential.Email     = email;

                                db.Entry(credential).State = EntityState.Added;
                                db.Credentials.Add(credential);
                                db.SaveChanges();
                                return(true);
                            }
                            else
                            {
                                MessageBox.Show("Username-ul introdus exista deja. Incercati unul nou", "Warning", MessageBoxButtons.OK);
                                return(false);
                            }
                        }
                        else
                        {
                            MessageBox.Show("Emailul introdus nu este valid. Incercati din nou", "Warning", MessageBoxButtons.OK);
                            return(false);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Exista deja un utilizator inregistrat cu acest Cod unic", "Warning", MessageBoxButtons.OK);
                        return(false);
                    }
                }
                else
                {
                    MessageBox.Show("Cod unic inexistent. Contactati administratorul pentru o cheie valida.", "Error", MessageBoxButtons.OK);
                    return(false);
                }
            }
        }