Exemplo n.º 1
0
        public int SaveUsersToRole(IUsersToRoleDb usersToRoleDb, int? transactionNumber = null)
        {
            if (usersToRoleDb.InstanceId != _instanceId)
                throw new Exception("Attempt to save UsersToRole with wrong InstanceId");

            UsersToRole record;
            var recordOld = new UsersToRole();
            if (usersToRoleDb.UserRoleId == 0)
            {
                record = new UsersToRole();
                Context.AddToUsersToRoles(record);
            }
            else
            {
                record = Context.UsersToRoles.Where(r => r.UserRoleId == usersToRoleDb.UserRoleId).First();
                ReflectionHelper.CopyAllProperties(record, recordOld);
            }

            record.InstanceId = _instanceId;
            record.UserId = usersToRoleDb.UserId;
            record.RoleId = usersToRoleDb.RoleId;

            Context.SaveChanges();
            if (usersToRoleDb.UserRoleId == 0)
            {
                usersToRoleDb.UserRoleId = record.UserRoleId;
                LogToDb(UserId, "UsersToRoles", record.UserRoleId, "I", XmlHelper.GetObjectXml(record), transactionNumber);
            }
            else
            {
                LogToDb(UserId, "UsersToRoles", record.UserRoleId, "U", XmlHelper.GetDifferenceXml(recordOld, record), transactionNumber);
            }

            return usersToRoleDb.UserRoleId;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the UsersToRoles EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToUsersToRoles(UsersToRole usersToRole)
 {
     base.AddObject("UsersToRoles", usersToRole);
 }
 public void AddToUsersToRoles(UsersToRole record)
 {
     _context.AddToUsersToRoles(record);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Create a new UsersToRole object.
 /// </summary>
 /// <param name="userRoleId">Initial value of the UserRoleId property.</param>
 /// <param name="instanceId">Initial value of the InstanceId property.</param>
 /// <param name="userId">Initial value of the UserId property.</param>
 /// <param name="roleId">Initial value of the RoleId property.</param>
 public static UsersToRole CreateUsersToRole(global::System.Int32 userRoleId, global::System.Int32 instanceId, global::System.Int32 userId, global::System.Int32 roleId)
 {
     UsersToRole usersToRole = new UsersToRole();
     usersToRole.UserRoleId = userRoleId;
     usersToRole.InstanceId = instanceId;
     usersToRole.UserId = userId;
     usersToRole.RoleId = roleId;
     return usersToRole;
 }