Esempio n. 1
0
 public override void DeleteUser(IUser user)
 {
     if (user == null)
     {
         throw new ArgumentNullException("user");
     }
     UserCache.RemoveUserFromCache(user);
     CurrentDB.ExecuteNonQuery("dbo.USER_Delete",
                               CurrentDB.CreateInputParameter("@guidUserID", DbType.Guid, new Guid(user.Id)));
 }
Esempio n. 2
0
        public override IUser GetUserById(string userId)
        {
            var user = UserCache.GetUserById(userId);

            if (user != null)
            {
                return(user);
            }

            var dsUser = CurrentDB.ExecuteDataSet("dbo.USER_GetByID",
                                                  CurrentDB.CreateInputParameter("@guidUserID", DbType.Guid, new Guid(userId)));

            user = GetUserFromDataSet(dsUser);
            UserCache.AddUserToCache(user);
            return(user);
        }
Esempio n. 3
0
        protected virtual void SaveProperty(IUser user, IProperty property, ITransaction transaction)
        {
            var propertyValue = string.Empty;

            if (!property.IsEmpty())
            {
                propertyValue = property.ToSerializedString();
            }

            if (propertyValue.Length > 0)
            {
                CurrentDB.ExecuteNonQuery("dbo.USER_UpdateProperty",
                                          transaction,
                                          CurrentDB.CreateInputParameter("@guidUserId", DbType.Guid, new Guid(user.Id)),
                                          CurrentDB.CreateStringInputParameter("@chvProperty", DbType.AnsiString, property.Name),
                                          CurrentDB.CreateStringInputParameter("@chvnPropertyValue",
                                                                               DbType.String,
                                                                               propertyValue.Length <= 4000 ? propertyValue : null),
                                          CurrentDB.CreateStringInputParameter("@txtnExtPropertyValue",
                                                                               DbType.String,
                                                                               propertyValue.Length > 4000 ? propertyValue : null),
                                          CurrentDB.CreateStringInputParameter("@chvContext",
                                                                               DbType.AnsiString,
                                                                               property.Context == null ||
                                                                               string.IsNullOrEmpty(property.Context.Name)
                                                                                                       ? null
                                                                                                       : property.Context.Name));
            }
            else
            {
                CurrentDB.ExecuteNonQuery("dbo.USER_DeleteProperty",
                                          transaction,
                                          CurrentDB.CreateInputParameter("@guidUserId", DbType.Guid, new Guid(user.Id)),
                                          CurrentDB.CreateStringInputParameter("@chvPropertyName", DbType.AnsiString, property.Name),
                                          CurrentDB.CreateStringInputParameter("@chvContextName",
                                                                               DbType.AnsiString,
                                                                               property.Context == null ||
                                                                               string.IsNullOrEmpty(property.Context.Name)
                                                                                                       ? null
                                                                                                       : property.Context.Name));
            }

            property.IsDirty = false;
        }
Esempio n. 4
0
        protected virtual IPropertyCollection GetPropertiesByUserId(string userId, IContext context)
        {
            IPropertyCollection upc = null;

            var dsUser = CurrentDB.ExecuteDataSet("dbo.USER_GetProperties",
                                                  CurrentDB.CreateInputParameter("@guidUserID", DbType.Guid, new Guid(userId)),
                                                  CurrentDB.CreateStringInputParameter("@chvContext",
                                                                                       DbType.AnsiString,
                                                                                       context == null ||
                                                                                       string.IsNullOrEmpty(context.Name)
                                                                                                               ? null
                                                                                                               : context.Name));

            // translate dataset
            if (dsUser.Tables.Count > 0)
            {
                dsUser.Tables[0].PrimaryKey = new[] { dsUser.Tables[0].Columns["PropertyName"] };
                var rows = dsUser.Tables[0].Rows;
                upc = GetPropertiesFromDataRows(rows, context, null);
            }
            return(upc);
        }
Esempio n. 5
0
        protected virtual void SaveUserInstance(IUser user, ITransaction transaction)
        {
            var dsUser = CurrentDB.ExecuteDataSet("dbo.USER_Update",
                                                  transaction,
                                                  CurrentDB.CreateInputParameter("@guidUserId",
                                                                                 DbType.Guid,
                                                                                 new Guid(user.Id)),
                                                  CurrentDB.CreateStringInputParameter("@chvnUsername",
                                                                                       DbType.String,
                                                                                       user.UserName,
                                                                                       false),
                                                  CurrentDB.CreateStringInputParameter("@chvDomain",
                                                                                       DbType.AnsiString,
                                                                                       user.Domain,
                                                                                       false));
            var status = (int)dsUser.Tables[0].Rows[0]["STATUS"];

            if (status == AddStatusUsernameTaken)
            {
                throw new UserNameAlreadyExistsException("Cannot save user. User name already exists.");
            }
        }
Esempio n. 6
0
        public override IList <IUser> GetAllUsers(int pageIndex, int pageSize, out int totalRecords)
        {
            var     returnParam = CurrentDB.CreateReturnParameter("@intPagingTotalNumber", DbType.Int32);
            DataSet dsUser;

            if (pageSize.Equals(int.MaxValue) || pageIndex.Equals(int.MaxValue))
            {
                dsUser = CurrentDB.ExecuteDataSet("dbo.USER_FilterUsers", returnParam);
            }
            else
            {
                dsUser = CurrentDB.ExecuteDataSet("dbo.USER_FilterUsers",
                                                  CurrentDB.CreateInputParameter("@intLimitPage", DbType.Int32, pageIndex + 1),
                                                  CurrentDB.CreateInputParameter("@intLimitSize", DbType.Int32, pageSize),
                                                  returnParam);
            }
            var uc = GetUsersFromDataSet(dsUser);

            UserCache.AddUsersToCache(uc);
            totalRecords = (int)returnParam.Value;
            return(uc);
        }