Esempio n. 1
0
        /// <summary>
        /// Insert an instance of User into storage
        /// </summary>
        /// <param name="iUser">The instance of user to insert</param>
        /// <returns>True if the insert was successful</returns>
        public Boolean InsertUser(User iUser)
        {
            Boolean pBlnCreatedTable = UsersTable.CreateIfNotExists();

            try
            {
                TableOperation pTOnInsert = TableOperation.Insert(iUser);
                TableResult    pTRtResult = UsersTable.Execute(pTOnInsert);
                switch (pTRtResult.HttpStatusCode)
                {
                case 200:
                case 204:
                {
                    Boolean pBlnRetVal;
                    pBlnRetVal = CreateDefaultUserProfile(iUser);
                    return(pBlnRetVal);
                }

                default:
                {
                    return(false);
                }
                }
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Get a user from storage by its given user principal
        /// </summary>
        /// <param name="iUserPrincipal">User principal of the user to get</param>
        /// <returns>The requested user, if found in storage, otherwise null</returns>
        public User GetUser(ClaimsPrincipal iUserPrincipal)
        {
            Boolean     pBlnCreatedTable = UsersTable.CreateIfNotExists();
            TableResult pTRtResult       = new TableResult()
            {
                HttpStatusCode = 404
            };

            if (pBlnCreatedTable)
            {
                return(null);
            }
            else
            {
                String         pStrPartitionKey = iUserPrincipal.GetUserPartitionKey(ClaimsPrincipalExtensions.KeySource.email);
                String         pStrRowKey       = iUserPrincipal.GetUserRowKey(ClaimsPrincipalExtensions.KeySource.email);
                TableOperation pTOnRetrieve     = TableOperation.Retrieve <User>(pStrPartitionKey, pStrRowKey);
                pTRtResult = UsersTable.Execute(pTOnRetrieve);
                switch (pTRtResult.HttpStatusCode)
                {
                case 200:
                {
                    return((User)pTRtResult.Result);
                }
                }
                return(null);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Replaces a user in the storage system
        /// </summary>
        /// <param name="iUser">User to replace</param>
        /// <returns>True if the operation was successful</returns>
        public Boolean Replace(User iUser)
        {
            TableOperation pTOnReplace = TableOperation.Replace(iUser);
            TableResult    pTRtResult  = UsersTable.Execute(pTOnReplace);

            return(pTRtResult.HttpStatusCode == 200 ||
                   pTRtResult.HttpStatusCode == 204);
        }