示例#1
0
 private Framework.RbacParameter Assign(RbacUserParameter parameter)
 {
     Framework.RbacParameter newParam = new Framework.RbacParameter();
     newParam.Name  = GetDecryptedString(parameter.Name);
     newParam.Value = GetDecryptedString(parameter.Value);
     return(newParam);
 }
        public Framework.RbacParameter AddOrUpdateUserParameter(int userId, string paramName, string paramValue)
        {
            Framework.RbacParameter parameter = new Framework.RbacParameter();
            parameter.Name  = paramName;
            parameter.Value = paramValue;
            byte[] bName = GetEncryptedString(paramName);
            try
            {
                using (var ctx = new Entities(ConnectionString))
                {
                    RbacUserParameter existingParameter = null;
                    existingParameter = ctx.RbacUserParameters.AsEnumerable().Where(r => ((r.UserId == userId) && (r.Name.SequenceEqual(bName)))).SingleOrDefault();

                    if (existingParameter == null)
                    {
                        RbacUserParameter newParam = new RbacUserParameter();
                        newParam.Name   = GetEncryptedString(paramName);
                        newParam.Value  = GetEncryptedString(paramValue);
                        newParam.UserId = userId;
                        ctx.RbacUserParameters.Add(newParam);
                    }
                    else
                    {
                        existingParameter.Value = GetEncryptedString(paramValue);
                    }

                    ctx.SaveChanges();
                }
            }
            catch (DbUpdateException dbe)
            {
            }
            catch (DbEntityValidationException e)
            {
                RaiseError(e);
            }
            return(parameter);
        }