Example #1
0
        /// <summary>
        /// Create new account, using Person entity, password, and optionally privilegies level.
        /// </summary>
        /// <param name="person"></param>
        /// <param name="password"></param>
        /// <param name="privilegies"></param>
        public static void CreateAccount(Person person, string password, char privilegies = 'c')
        {
            using (var tx = Client.GetTransactions().TxStart())
            {
                // Referential integrity check
                if (CredentialCache.ContainsKey(person.Phone))
                {
                    tx.Commit();
                    throw new ReferentialException("Can not create new account.")
                          {
                              ReadableMessage = $"Can not create account because account with phone {person.Phone} already exists."
                          };
                }
                if (!LocationCache.ContainsKey(person.LocationID))
                {
                    tx.Commit();
                    throw new ReferentialException("Can not create new account.")
                          {
                              ReadableMessage = $"Can not create account because location with key {person.LocationID} does not exist."
                          };
                }

                // Normal operation
                int key = LastUsedKeys.Get("person");
                PersonCache.Put(key, person);
                LastUsedKeys.Put("person", key + 1);

                Credential c = new Credential
                {
                    Password    = password,
                    Privilegies = (byte)privilegies,
                    Status      = (byte)'n',
                    PersonID    = key
                };

                CredentialCache.Put(person.Phone, c);
                tx.Commit();
            }
        }
Example #2
0
 /// <summary>
 /// Put credential in cache and assign string key which is the phone number of the referenced person.
 /// </summary>
 /// <param name="value">Credential to put in the cache.</param>
 public static void PutCredential (Credential value)
 {
     using (var tx = Client.GetTransactions().TxStart())
     {
         if (PersonCache.ContainsKey(value.PersonID)) 
         {
             CredentialCache.Put (PersonCache.Get(value.PersonID).Phone, value);
             tx.Commit();
         }
         else 
         { 
             tx.Commit();
             throw new ReferentialException ("Can not put new entry into Credential cache.")
             {
                 Operation = "put",
                 TableName = "Credential",
                 FieldName = "PersonID",
                 ReadableMessage = $"Can not put new entry into Credential cache because Person with key {value.PersonID} does not exist."
             };
         }
     }
 }