/// <summary>
 /// Veraltete Methode zum Hinzufügen eines neuen Objekts zum EntitySet 'USER'. Verwenden Sie stattdessen die Methode '.Add' der zugeordneten Eigenschaft 'ObjectSet&lt;T&gt;'.
 /// </summary>
 public void AddToUSER(USER uSER)
 {
     base.AddObject("USER", uSER);
 }
Exemplo n.º 2
0
        private static bool HasRight(USER user, RIGHT right)
        {
            if (user.ISADMIN.HasValue && user.ISADMIN.Value)
            {
                return true;
            }

            var uId = user.ID;
            var rId = right.ID;

            using (var en = new HaushaltsrechnerEntities())
            {
                return en.USER.Any(u => u.ID == uId && u.RIGHT.Any(r => r.ID == rId));
            }
        }
 /// <summary>
 /// Erstellt ein neues USER-Objekt.
 /// </summary>
 /// <param name="id">Anfangswert der Eigenschaft ID.</param>
 /// <param name="nAME">Anfangswert der Eigenschaft NAME.</param>
 public static USER CreateUSER(global::System.Guid id, global::System.String nAME)
 {
     USER uSER = new USER();
     uSER.ID = id;
     uSER.NAME = nAME;
     return uSER;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Adds a <see cref="HaushaltsRechner.Data.Model.USER"/>.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="pw">The password.</param>
        /// <param name="sysAdmin">if set to <c>true</c> System Admin flag will be set.</param>
        /// <returns><c>true</c>, if addition successfull</returns>
        public static bool AddUser(string name, string pw, bool sysAdmin)
        {
            if (name == string.Empty)
            {
                return false;
            }

            using (var en = new HaushaltsrechnerEntities())
            {
                var pass = string.Empty;

                var testUser = en.USER.FirstOrDefault(u => u.NAME == name);

                if (testUser != null)
                {
                    return false;
                }

                if (pw != string.Empty)
                {
                    byte[] encrypted = Cryptography.EncryptStringToBytes_AES(pw);

                    foreach (var e in encrypted)
                    {
                        pass += (char)e;
                    }
                }

                var user = new USER
                {
                    NAME = name,
                    PASSWORT = pass,
                    ISADMIN = sysAdmin,
                    ID = Guid.NewGuid()
                };
                en.USER.AddObject(user);
                en.SaveChanges();
                return true;
            }
        }